PHP相当于python的三引号 - 如何在PHP中打印批量/大量HTML而不转义

Ale*_*cer 9 php python language-comparisons codeigniter heredoc

可能重复:
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
"""
Run Code Online (Sandbox Code Playgroud)

有人知道PHP是否具有与python相同的功能

""" <form><h1>PUT HTML HERE</h1> </form> """
enter code here
Run Code Online (Sandbox Code Playgroud)

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

$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

Mic*_*ior 10

您可以使用here文档或nowdocs(见下文here文档).

定界符

$bar = <<<EOT
bar
EOT;
Run Code Online (Sandbox Code Playgroud)

Nowdoc

$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
Run Code Online (Sandbox Code Playgroud)

  • 谢谢迈克尔。您会为我浪费多少时间在功能中转义而感到惊讶...。非常感谢! (2认同)