9

可能重复:
php 字符串转义,如 python 的“”“”“”?

python 中的三引号会转义其中包含的所有引号和换行符。例如,

""" this
is all


just one string. I can even tell you "I like pi".
Notice that the single quotes are escaped - they don't end the string; and the newlines become part of the string
"""

有谁知道 PHP 是否有与 python 的等价物

""" <form><h1>PUT HTML HERE</h1> </form> """
enter code here

编辑:对于那些在未来看这个问题的人,我已经回答了,这里有一个例子:

$heading = "Heading Gettizburgz"; print <<< END <p><h1>$heading</h1> "in quotes" 'in single' Four score and seven years ago<br/> our fathers set onto this continent<br/> (and so on ...)<br/> </p> END;

印刷: Heading Gettizburgz "in quotes" 'in single' Four score and seven years ago our fathers set onto this continent (and so on ...)

请注意一件重要的事情,您必须确保最后一个END位于代码的最左侧(第一列),前面没有任何空格。

来源:http ://alvinalexander.com/blog/post/php/php-here-document-heredoc-syntax-examples

4

1 回答 1

10

您可以使用heredocs或 nowdocs(请参阅下面的 heredocs)。

赫雷多克

$bar = <<<EOT
bar
EOT;

诺多克

$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
于 2012-12-17T22:50:41.923 回答