簡體   English   中英

我該如何替換` <?php echo …; ?> 帶有`的表達式 <?= ?> `?

[英]How can I replace `<?php echo …; ?>` expression with `<?= ?> `?

從php 5.4開始, <?= ...?>可用於替換<?php echo ...;?>

因此,我想在項目中的.php文件中替換所有這些文件。 我該如何更換它們?

還是不能自動轉換?

我發現了用[]thomasbachem / php-short-array-syntax-converter )替換array()的腳本。 有人知道這樣嗎?

(這可能存在於任何地方,但谷歌很難通過帶有許多符號的查詢來搜索...)

在PHP 5.4.0中,無論short_open_tag ini設置如何,標記<?=..始終可用。 資源

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 ?>更改為<?= ?>

如果您在php.ini中啟用了short_open_tags,則可以使用<?= ...?>代替默認的打開標記。

至於轉換所有程序語句

<?php
echo $var;
?>

<?=$var ?>

將必須手動完成。 盡管我在github上發現了一些反向腳本(將短標簽轉換為長標簽),但我不知道有任何腳本可以自動執行該腳本。

在您的php.ini中,更改標簽:
short_open_tag =關閉至:
short_open_tag =開啟 那會解決你的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM