Skip to content
WJunction - Webmaster Forum

php string - heredoc syntax

Status
Not open for further replies.
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

The only reason I don't use it is that it looks damn wierd compared to the rest of PHP syntax, and kinda throws me off.
 
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.

About the author

D
Senior Member · Joined
coding in php and python
1,544
Messages
7
Reactions
38
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom