How do I find documentation on =<<<

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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

How do I find documentation on =<<<

Post by neophyte »

I'm trying to find documentation on php.net on "$template =<<< STOP;" but I'm not sure what to search for and I can't find it.

What do you call it?
feyd wrote:

Code: Select all

&lt;?php

$template =&lt;&lt;&lt;STOP
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{TITLE}&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div style=&quote;text-align:right; border: 2px red solid; background-color: yellow; color: blue; padding: 10px 10px 10px 10px; font-weight: bold;&quote;&gt;{ERROR_DATA}&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
STOP;

?&gt;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

heredoc
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Thanks Feyd
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

This is interesting.
In the php manual (http://in.php.net/types.string),
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

How is any different/better than
$str = "
Example of string
spanning multiple lines
not using heredoc syntax.";
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

php manual wrote: Heredoc text behaves just like a double-quoted string, without the double-quotes. This means that you do not need to escape quotes in your here docs, but you can still use the escape codes listed above. Variables are expanded, but the same care must be taken when expressing complex variables inside a here doc as with strings.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

If you're going to still need large blocks of text hardwired into your script without variable decompression (?word choice?), you may want to consider trying to seperate this info from the script, or, if all else fails, "Output Buffering". http://us2.php.net/manual/en/function.ob-start.php You shouldn't have to have huge blocks of text in your PHP script, by structuring your code correctly, it should be able to be ported to other files or databases.
Post Reply