我刚刚阅读了 heredocs 但我没有看到任何正确意图代码的方法.这在php中可能吗?
I just read thought php doucmentation for heredocs but I did not see any way to intent the code properly. Is this possible in php?
现在我正在这样做,但这不利于可读性.
Right now I am doing this, but this is bad for readability.
<?php
if(something){
...
echo <<< END
This is a test. I am writing this
text out.
END;
} # end of if statment
我想要这样的东西:
<?php
if(something){
...
echo <<< END
This is a test. I am writing this
text out.
END;
} # end of if statment
我知道 bash 有一个方法可以做到这一点(虽然我不记得它是什么),所以我想知道是否可以在 php.ini 中做到这一点.我不这么认为,但我想我会问.
I know that bash has a method to do this (although I cannot remember what it is), so I was wondering if it was possible to do in php. I don't think so but I thought I would ask.
正确格式化 Heredoc 语句是 PHP 的一个限制.这是解析器的限制.正如文档所述:
It's a limitation of PHP to properly format Heredoc statements. It's a parser limitation. As the documentation states:
请务必注意,必须与结束标识符行不包含其他字符,除了可能是分号 (;).这意味着特别是标识符可能不会缩进,并且可能没有任何之前或之后的空格或制表符分号.同样重要的是意识到第一个字符必须在结束标识符之前本地定义的换行符操作系统.这是 UNIX 上的 系统,包括 Mac OS X.结束分隔符(可能跟在后面分号)也必须跟在后面换行符.
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 on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.
如果这条规则被打破并且结束标识符不是干净",它不会被视为关闭标识符,PHP 将继续找一个.如果一个适当的之前未找到关闭标识符当前文件的结尾,一个解析错误将出现在最后一行.
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.
不知道这是否会在 PHP 的未来得到解决.
It's unknown if this is gonna be resolved in the future of PHP.
这篇关于PHP:在 Heredocs 中使用正确的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!