[PHP] Re: newbie question - php parsing

2009-07-23 Thread Peter Ford
João Cândido de Souza Neto wrote:
 You made a mistake in your code:
 
 ?php the_title(); ?
 
 must be:
 
 ?php echo the_title(); ?
 

Not necessarily: what if you have

function the_title()
{
echo Title;
}

for example...


In response to Sebastiano:

There would be not much point in using something like PHP if it ignored the if
statements in the code!
What effectively happens in a PHP source file is that all the bits outside of
the ?php ? tags are treated like an echo statement (except that it handles
quotes and stuff nicely)

Your original code:

?php if (the_title('','',FALSE) != 'Home') { ?
h2 class=entry-header?php the_title(); ?/h2
?php } ?

can be read like:

?php
if (the_title('','',FALSE) != 'Home') {
echo 'h2 class=entry-header';
the_title();
echo '/h2';
}
?

You might even find a small (but probably really, really, really small)
performance improvement if you wrote it that way, especially if it was in some
kind of loop.
Note that I prefer to keep HTML separate from PHP as much as possible because it
helps me to read it and helps my editor check my syntax and HTML structure 
better...


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: newbie question - php parsing

2009-07-23 Thread Sebastiano Pomata
Thanks, it's now much more clear. I thought that html parts outside
php tags were just dumped to output, no matter of if-else statements
and other conditions. I was *definitely* wrong

2009/7/23 Peter Ford p...@justcroft.com:

 In response to Sebastiano:

 There would be not much point in using something like PHP if it ignored the 
 if
 statements in the code!
 What effectively happens in a PHP source file is that all the bits outside of
 the ?php ? tags are treated like an echo statement (except that it handles
 quotes and stuff nicely)

 Your original code:

 ?php if (the_title('','',FALSE) != 'Home') { ?
 h2 class=entry-header?php the_title(); ?/h2
 ?php } ?

 can be read like:

 ?php
 if (the_title('','',FALSE) != 'Home') {
    echo 'h2 class=entry-header';
    the_title();
    echo '/h2';
 }
 ?

 You might even find a small (but probably really, really, really small)
 performance improvement if you wrote it that way, especially if it was in some
 kind of loop.
 Note that I prefer to keep HTML separate from PHP as much as possible because 
 it
 helps me to read it and helps my editor check my syntax and HTML structure 
 better...


 --
 Peter Ford                              phone: 01580 89
 Developer                               fax:   01580 893399
 Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: newbie question - php parsing

2009-07-22 Thread Jo�o C�ndido de Souza Neto
You made a mistake in your code:

?php the_title(); ?

must be:

?php echo the_title(); ?

-- 
João Cândido de Souza Neto
SIENS SOLUÇÕES EM GESTÃO DE NEGÓCIOS
Fone: (0XX41) 3033-3636 - JS
www.siens.com.br

Sebastiano Pomata lafayett...@gmail.com escreveu na mensagem 
news:70fe20d60907221355m3fa49a75ua053d2f1b9aca...@mail.gmail.com...
 Hi all,

 A little doubt caught me while I was writing this snippet of code for
 a wordpress template:

 ?php if (the_title('','',FALSE) != 'Home') { ?
 h2 class=entry-header?php the_title(); ?/h2
 ?php } ?

 I always thought that php was called only between the ?php ? tags,
 and I'm pretty sure that's right, while HTML code was simply wrote in
 document as is, without further logic.
 Now, I can't figure out how this snippet works: I mean, shouldn't HTML
 code be simply put on document, as it is outside php invoke?
 Effectively if the title of page is 'Home', the HTML part is totally
 skipped.

 Is the if construct that does all the magic inside? 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Shane Hill
2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br

 You made a mistake in your code:

 ?php the_title(); ?

 must be:

 ?php echo the_title(); ?


?= the_title(); ?

also works.

-Shane





 --
 João Cândido de Souza Neto
 SIENS SOLUÇÕES EM GESTÃO DE NEGÓCIOS
 Fone: (0XX41) 3033-3636 - JS
 www.siens.com.br

 Sebastiano Pomata lafayett...@gmail.com escreveu na mensagem
 news:70fe20d60907221355m3fa49a75ua053d2f1b9aca...@mail.gmail.com...
  Hi all,
 
  A little doubt caught me while I was writing this snippet of code for
  a wordpress template:
 
  ?php if (the_title('','',FALSE) != 'Home') { ?
  h2 class=entry-header?php the_title(); ?/h2
  ?php } ?
 
  I always thought that php was called only between the ?php ? tags,
  and I'm pretty sure that's right, while HTML code was simply wrote in
  document as is, without further logic.
  Now, I can't figure out how this snippet works: I mean, shouldn't HTML
  code be simply put on document, as it is outside php invoke?
  Effectively if the title of page is 'Home', the HTML part is totally
  skipped.
 
  Is the if construct that does all the magic inside?



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Lenin
Ted Turner http://www.brainyquote.com/quotes/authors/t/ted_turner.html  -
Sports is like a war without the killing.

2009/7/23 Shane Hill shanehil...@gmail.com

 2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br

  You made a mistake in your code:
 
  ?php the_title(); ?
 
  must be:
 
  ?php echo the_title(); ?


 ?= the_title(); ?


Short tag and not recommended as its deprecated now, would be void at PHP
6.0


Re: [PHP] Re: newbie question - php parsing

2009-07-22 Thread Martin Scotta
This is how I'd write this snippet

?php
if ( 'Home' !== ( $title = the_title('','',FALSE)))
{
echo 'h2 class=entry-header',
$title,
'/h2';
}
?

On Wed, Jul 22, 2009 at 6:31 PM, Lenin le...@phpxperts.net wrote:

 Ted Turner http://www.brainyquote.com/quotes/authors/t/ted_turner.html
  -
 Sports is like a war without the killing.

 2009/7/23 Shane Hill shanehil...@gmail.com

  2009/7/22 João Cândido de Souza Neto j...@consultorweb.cnt.br
 
   You made a mistake in your code:
  
   ?php the_title(); ?
  
   must be:
  
   ?php echo the_title(); ?
 
 
  ?= the_title(); ?


 Short tag and not recommended as its deprecated now, would be void at PHP
 6.0




-- 
Martin Scotta


[PHP] Re: newbie question - php parsing

2009-07-22 Thread Shawn McKenzie
João Cândido de Souza Neto wrote:
 You made a mistake in your code:
 
 ?php the_title(); ?
 
 must be:
 
 ?php echo the_title(); ?
 

I haven't used worpress in a long time, but the the_title() function
might echo the title unless you pass the FALSE parameter, in which case
it just returns it.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php