question about php ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rukix1x
Forum Newbie
Posts: 5
Joined: Thu Nov 25, 2010 11:35 pm

question about php ...

Post 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 .
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: question about php ...

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: question about php ...

Post 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();
?>
NeooeN
Forum Newbie
Posts: 8
Joined: Sun Nov 28, 2010 10:08 am

Re: question about php ...

Post 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.
rukix1x
Forum Newbie
Posts: 5
Joined: Thu Nov 25, 2010 11:35 pm

Re: question about php ...

Post by rukix1x »

Thanks guys ! I understand it now. I really appreciate your help. :)
Post Reply