gpt4 book ai didi

PHP Heredoc 字符串规则

转载 作者:可可西里 更新时间:2023-11-01 13:34:58 25 4
gpt4 key购买 nike

这里有人可以探索使用 heredoc 的复杂性吗?在 PHP 中使用示例 PHP 代码片段,基于手册下面的内容?

php.net 手册说:

It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables.

这里是 PHP 手册的链接:http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

最佳答案

这是一个简单的用法:

$bar = "stackoverflowpro";
$foo = <<<HTML
<p>Hello $bar</p>
HTML;

关于PHP Heredoc 字符串规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7581315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com