聘我网

新概念招聘3.0

PHP告别冗余的echo!

vote up0vote downstar
<?php

$a=1;

?>
<?=$a+1;?>

原来<?= $a ?>等价于<? echo $a; ?>

以前一度以为PHP中没有这种写法,所以导致模板文件中无数的echo,以后代码将更加精简。

不过这种写法有个使用条件:

Short tags (example three) are only available when they are enabled via the shortopentag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option.

更新

可以var_dump(token_get_all('<?=$a;?>'));看个究竟

参考文献:

http://www.php.net/manual/en/tokens.php

http://www.php.net/manual/en/language.basic-syntax.phpmode.php

更新

现在发现这样会导致兼容性问题,还是回到echo派比较保险。。

 

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.