Using <<<CON in PHP

陌路散爱 提交于 2019-12-11 04:47:22

问题


What is the effect of the following code?

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

What does the <<<CON do?


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/2090081/using-con-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!