php string - heredoc syntax

Status
Not open for further replies.

desiboy

Active Member
1,544
2008
7
0
its very basic, but not many use it ..

PHP:
<?php
$var1 = "Wjunction";
$string1 = <<< EOD
I am a bot <br /> 
I <3 $var1 <br />
I need not be escaped , let's test <br />
EOD;
echo $string1;
?>
EOD stands for end of data

Advantages : no need to escape quotes in the string itself..

I donno about the disadvantages.. if you know any , please post it here :)
 
3 comments
i find it a lot easier to use, compared to breaking in and out of html<->php all the time, which to me looks messy.
i haven't found any disadvantage to EOD yet, apart from when I wanted to run a php function from inside the EOD area, i had to put braces around the code {$phpobject->run()}, other than that it seems to work smoothly for just about every scenario i could imagine.

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
 
btw..


PHP:
<?php
$var1 = "Wjunction";
$string1 = <<< WJUNCTION
I am a bot <br /> 
I <3 $var1 <br />
I need not be escaped , let's test <br />
WJUNCTION;
echo $string1;
?>
will work ;)
 
Status
Not open for further replies.
Back
Top