2016-05-29 43 views
1

從php 5.4開始,<?= ...?>可用於替換<?php echo ...;?>我該如何取代`<?php echo ...; ?``用`<?= ?>`表達``表達?

所以我想在我的項目中替換.php文件中的所有文件。我該如何替換它們?

還是不能自動轉換?

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

(這可能存在的任何地方,但它是很難爲谷歌用很多符號查詢搜索...)

+0

你需要在'php.ini'中改變。 _short_open_tag默認值:On_ –

+1

@FrayneKonok我假設OP使用PHP 5.4+。如果是這種情況,無論php.ini中的值如何,始終都可以使用<?= =。 – Mike

+0

尋找'short_open_tag = Off'如果沒有,就把它打開。 –

回答

0

如果你在php.ini文件中激活項short_open_tags,你將能夠使用<?= ...?>而不是默認的開放標籤。

至於如將所有的程序語句從

<?php 
echo $var; 
?> 

<?=$var ?> 

都必須手動完成。我不知道任何轉換器腳本自動化,儘管我在github上發現了一些反過來的腳本(將短標籤轉換爲長標籤)。

+0

這個問題是針對PHP 5.4的。能夠使用''[永遠在線](http://php.net/manual/en/language.basic-syntax.phptags.php) – Terminus

+0

謝謝你的回答。我知道將'<?php echo'自動轉換爲'<?='似乎很困難...... – ikuwow

0

在PHP 5.4.0,標籤<?=..始終可用無論short_open_tag INI設置。 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

*之後,您可以將更改爲 * - 這是此問題的要點。OP正在詢問如何自動執行此操作。其餘的答案並不真正回答這個問題。 – Mike

+0

這個問題是針對PHP 5.4的。能夠使用''[永遠在線](http://php.net/manual/en/language.basic-syntax.phptags.php) – Terminus

+0

如果有人手動關閉它然後什麼,我只是建議OP檢查和使用。 –

-1
在php.ini

更改標籤:
short_open_tag的值爲=關到:
short_open_tag的值爲=在。那可以解決你的問題

相關問題