如何替换`<! - ?php echo ...; ? - >`表达式与`<! - ?=? - >`?

时间:2016-05-29 03:41:35

标签: php arrays

从php 5.4开始,<?= ...?>可用于替换<?php echo ...;?>

所以我想在项目的.php文件中替换所有这些文件。我该如何更换它们?

或者可以自动转换?

我找到了用array()thomasbachem/php-short-array-syntax-converter)替换[]的脚本。有谁知道这样的事情?

(这可能存在于任何地方,但Google很难通过带有多个符号的查询进行搜索...)

3 个答案:

答案 0 :(得分:0)

在PHP 5.4.0中,无论<?=.. ini设置如何,标记short_open_tag始终可用。 Source

<强>的php.ini

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag=Off
  

之后,您可以将<?php echo ?>更改为<?= ?>

答案 1 :(得分:0)

如果您在php.ini中启用了short_open_tags,则可以使用<?= ...?>而不是默认的开放标记。

至于从

转换所有程序语句
<?php
echo $var;
?>

<?=$var ?>

必须手动完成。我不知道有任何转换器脚本可以自动化它,虽然我在github上发现了一些相反的脚本(将短标签转换为长标签)。

答案 2 :(得分:-1)

在你的php.ini中

更改标签:
short_open_tag =关闭:
 的 short_open_tag的值为=开即可。这将解决你的问题