ENDOFSTRING PHP Strings


/ Published in: PHP
Save to your folder(s)

Here's a handy (relatively undocumented) tip. PHP supports the following method of assigning strings (borrowed from Perl)


Copy this code and paste it in your HTML
  1. $string = <<<ENDOFSTRING
  2. This is a string
  3.  
  4. It can include both 'single' and "double" quotes
  5. without needing to escape them. However, $variables
  6. will still be interpolated as they are in double
  7. quoted strings. Complex variable expressions such as
  8. {$array['element']} or {$object->property} can also
  9. be included and will be evaluated if they are included
  10. in curly braces (they may work without curly braces
  11. but I tend to include them for added clarity). The
  12. string will terminate with whatever you specified
  13. at the start like this:
  14. ENDOFSTRING;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.