Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <<<CON in PHP

What is the effect of the following code?

$page = <<<CON
<p><center>Blah blah blah</center></p>
CON;

What does the <<<CON do?

like image 665
waiwai933 Avatar asked Aug 17 '26 13:08

waiwai933


2 Answers

This is known as heredoc. It's essentially a way of defining the value of a variable that spans multiple lines, and doesn't require escaping like traditional strings. The "CON" part is merely an identifier that represents the start and end of the value. This can be changed to a more familiar value.

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
like image 99
Sampson Avatar answered Aug 20 '26 20:08

Sampson


That's the PHP heredoc operator. Details at this link:

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

like image 31
Don Neufeld Avatar answered Aug 20 '26 19:08

Don Neufeld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!