<?=$value?>和& lt; ?echo $价值;祝辞


Is there any difference between <?=$value?> and <? echo $value; ?>

环境:Windows/7 + Apache/2.2.21 + PHP/5.3.8

test.php的文件内容:

hello, <?=$test?>

index1.php文件内容:

<?php
$test = 'world';
require './test.php';
?>

index2.php文件内容:

<?php
global $test;
$test = 'world';
require './test.php';
?>

index1.php的输出为:

hello,

index2.php的输出为:

hello, world

test.php的内容为:

hello, <? echo $test; ?>

index1.phpindex2.php的输出均为:

hello, world

所以,我的问题是:<?=$test?><? echo $test; ?>有什么区别吗?

不,没有区别。我唯一想到的是<?被认为是短标记,可能不起作用。

有一点不同,这可能非常非常烦人。如果在php.ini中将short_open_tag设置为false,则会收到大量错误。

在任何情况下,?>之前的最后一个;是可选的

<?=$x;?><? echo $x; ?>在这方面没有输出差异。

尽管我认为这种包含活动PHP文件的技术在这种特定情况下并不是最佳实践。

Shai .