/ Published in: PHP
Here's a handy (relatively undocumented) tip. PHP supports the following method of assigning strings (borrowed from Perl)
Expand |
Embed | Plain Text
$string = <<<ENDOFSTRING This is a string It can include both 'single' and "double" quotes without needing to escape them. However, $variables will still be interpolated as they are in double quoted strings. Complex variable expressions such as {$array['element']} or {$object->property} can also be included and will be evaluated if they are included in curly braces (they may work without curly braces but I tend to include them for added clarity). The string will terminate with whatever you specified at the start like this: ENDOFSTRING;
Comments
Subscribe to comments
You need to login to post a comment.

The 3 < signs are necessary?
This is known as HEREDOC syntax (http://bit.ly/j5IAU) ...it's useful for very long bits of text, but not great at all for performance. What is generally better is to use single quotes for strings and append variables that way the parser doesn't have to search the entire string first for variables (although you lose the ability to not escape double and single quotes). Then again, if you plan on just echoing back the entire string, you don't have to make an call at all...and in fact it works great since the php parser will completely ignore it:
The above snip should be: