PHP:在 Heredocs 中使用正确的缩进
我刚刚阅读了 heredocs 但我没有看到任何方法来正确地意图代码。这在 php 中可能吗?
现在我正在这样做,但这不利于可读性。
<?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中做到这一点。我不这么认为,但我想我会问。
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
I would like to have something like this:
<?php
if(something){
...
echo <<< END
This is a test. I am writing this
text out.
END;
} # end of if statment
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 无法正确格式化 Heredoc 语句,这是 PHP 的一个限制。这是解析器的限制。正如文档所述:
尚不清楚这个问题是否会在 PHP 的未来得到解决。
It's a limitation of PHP to properly format Heredoc statements. It's a parser limitation. As the documentation states:
It's unknown if this is gonna be resolved in the future of PHP.
AFAIK,这是不可能的,您需要放置结束定界符标识符,没有任何空格/制表符/缩进:(
AFAIK, that's not possible, you need to put closing heredoc identifier without any spaces/tabs/indentation :(