首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将`<?php echo .;?>`表达式替换为`<?= ?> `?

如何将`<?php echo .;?>`表达式替换为`<?= ?> `?
EN

Stack Overflow用户
提问于 2016-05-29 03:41:34
回答 3查看 83关注 0票数 1

从php5.4中,可以使用<?= ...?>替换<?php echo ...;?>

因此,我想在我的项目中替换.php文件中的所有这些文件。我该怎么换呢?

或者它不能自动转换吗?

我找到了用[] (thomasbachem/php短数组语法转换器)代替[]的脚本。有人知道这种事吗?

(这可能在任何地方都存在,但是google很难通过有许多符号的查询进行搜索.)

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-05-29 03:51:57

如果在short_open_tags中启用了php.ini,则可以使用<?= ...?>代替默认的打开标记。

将所有程序语句转换为

代码语言:javascript
复制
<?php
echo $var;
?>

代码语言:javascript
复制
<?=$var ?>

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

票数 0
EN

Stack Overflow用户

发布于 2016-05-29 03:51:53

在PHP5.4.0中,标记<?=..总是可用的,而不管short_open_tag ini设置如何。来源

php.ini

代码语言:javascript
复制
; 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 ?>更改为<?= ?>

票数 0
EN

Stack Overflow用户

发布于 2016-05-30 20:54:49

在您的php.ini中更改标记:

short_open_tag=Off到:

short_open_tag=On.那就解决了你的问题

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37505937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档