Page 1 of 1

question about php ...

Posted: Mon Nov 29, 2010 10:26 am
by rukix1x
i am new here and i'm learning php. i have a question ... here is a code:

Code: Select all

<?php
function display(){

 ?>
<p>Hello</p>
<?php
 }
 display();
?>

why is it that i have to call display() for <p>Hello</p> to be displayed on the screen?
how does it happen? even though the paragraph element is not inside the php tags, it seems that
as if the <p> element is inside scope of the display() function. please tell me about this for me
to understand further. thanks .

Re: question about php ...

Posted: Mon Nov 29, 2010 11:29 am
by Celauran
rukix1x wrote:even though the paragraph element is not inside the php tags, it seems that
as if the <p> element is inside scope of the display() function.
That's exactly right.

Re: question about php ...

Posted: Mon Nov 29, 2010 12:54 pm
by califdon
rukix1x wrote:

Code: Select all

<?php
function display(){
 ?>
<p>Hello</p>
<?php
 }
 display();
?>
is exactly the same as:

Code: Select all

<?php
function display(){
   echo "<p>Hello</p>";
 }
display();
?>

Re: question about php ...

Posted: Mon Nov 29, 2010 1:17 pm
by NeooeN
Everywhere in the php code you can close it (by "?>") and paste there whatever you like so the parser will leave the code which is not between "<? ?>" tags and just print this to the output (send it to the browser in most cases). This kind of behaviour is called "Escaping from HTML" by the php documentation and is described here: http://www.php.net/manual/en/language.b ... hpmode.php. I hope it was helpful.

Re: question about php ...

Posted: Mon Nov 29, 2010 5:11 pm
by rukix1x
Thanks guys ! I understand it now. I really appreciate your help. :)