1. <legend id='D2dSQ'><style id='D2dSQ'><dir id='D2dSQ'><q id='D2dSQ'></q></dir></style></legend>
  2. <i id='D2dSQ'><tr id='D2dSQ'><dt id='D2dSQ'><q id='D2dSQ'><span id='D2dSQ'><b id='D2dSQ'><form id='D2dSQ'><ins id='D2dSQ'></ins><ul id='D2dSQ'></ul><sub id='D2dSQ'></sub></form><legend id='D2dSQ'></legend><bdo id='D2dSQ'><pre id='D2dSQ'><center id='D2dSQ'></center></pre></bdo></b><th id='D2dSQ'></th></span></q></dt></tr></i><div id='D2dSQ'><tfoot id='D2dSQ'></tfoot><dl id='D2dSQ'><fieldset id='D2dSQ'></fieldset></dl></div>
      <bdo id='D2dSQ'></bdo><ul id='D2dSQ'></ul>

  3. <tfoot id='D2dSQ'></tfoot>

      <small id='D2dSQ'></small><noframes id='D2dSQ'>

    1. PHP:在 Heredocs 中使用正确的缩进

      时间:2024-04-13

        <i id='ulgIA'><tr id='ulgIA'><dt id='ulgIA'><q id='ulgIA'><span id='ulgIA'><b id='ulgIA'><form id='ulgIA'><ins id='ulgIA'></ins><ul id='ulgIA'></ul><sub id='ulgIA'></sub></form><legend id='ulgIA'></legend><bdo id='ulgIA'><pre id='ulgIA'><center id='ulgIA'></center></pre></bdo></b><th id='ulgIA'></th></span></q></dt></tr></i><div id='ulgIA'><tfoot id='ulgIA'></tfoot><dl id='ulgIA'><fieldset id='ulgIA'></fieldset></dl></div>
          <bdo id='ulgIA'></bdo><ul id='ulgIA'></ul>
        • <legend id='ulgIA'><style id='ulgIA'><dir id='ulgIA'><q id='ulgIA'></q></dir></style></legend>
          <tfoot id='ulgIA'></tfoot>

          <small id='ulgIA'></small><noframes id='ulgIA'>

            <tbody id='ulgIA'></tbody>

              1. 本文介绍了PHP:在 Heredocs 中使用正确的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我刚刚阅读了 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 中使用正确的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 PHP 中从 SQL 格式化时间戳的最简单方法是什么? 下一篇:WordPress 致命错误:第 1832 行 wp-includes/wp-db.php 中允许的内存大小为 5368

                相关文章

                  <bdo id='KDljN'></bdo><ul id='KDljN'></ul>

              2. <small id='KDljN'></small><noframes id='KDljN'>

                <i id='KDljN'><tr id='KDljN'><dt id='KDljN'><q id='KDljN'><span id='KDljN'><b id='KDljN'><form id='KDljN'><ins id='KDljN'></ins><ul id='KDljN'></ul><sub id='KDljN'></sub></form><legend id='KDljN'></legend><bdo id='KDljN'><pre id='KDljN'><center id='KDljN'></center></pre></bdo></b><th id='KDljN'></th></span></q></dt></tr></i><div id='KDljN'><tfoot id='KDljN'></tfoot><dl id='KDljN'><fieldset id='KDljN'></fieldset></dl></div>
                  1. <legend id='KDljN'><style id='KDljN'><dir id='KDljN'><q id='KDljN'></q></dir></style></legend>

                    <tfoot id='KDljN'></tfoot>