环境: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.php
和index2.php
的输出均为:
hello, world
所以,我的问题是:<?=$test?>
和<? echo $test; ?>
有什么区别吗?
不,没有区别。我唯一想到的是<?
被认为是短标记,可能不起作用。
有一点不同,这可能非常非常烦人。如果在php.ini中将short_open_tag
设置为false,则会收到大量错误。
在任何情况下,?>
之前的最后一个;
是可选的
<?=$x;?>
和<? echo $x; ?>
在这方面没有输出差异。
尽管我认为这种包含活动PHP文件的技术在这种特定情况下并不是最佳实践。
Shai .