Heredoc

Assigning a user defined text label to a variable to hold a string of text, using <<<DELIMITER at the beginning of the assignment and (the same) LABEL followed by a semi-colon ; to identify the end of the string.

 

  • <<< informs PHP that you want to enter heredoc mode
  • DELIMITER can be anything you like, TEXT or anything else could be used
  • Single and Double quotes do not need escaping
  • Variables will be interpolated, i.e. The value of $myVar will be substituted within the string
  • $ should be escaped if you want it displayed, i.e. \$myVar
  • Delimiter DELIMITER; identifies the end of the string. MUST be in the the first column of a new line, with NO spaces around it.

*Note: The Delimiter MUST be in the the first column of a new line, with NO spaces around it.

 

 

 

Can also be used without assigning to a var, say if you just wanted to echo it as content:

*Note: The Delimiter MUST be in the the first column of a new line, with NO spaces around it.

Leave a Reply