include的应用,附带require的对比!
—————a_include.php——————
<?php
/**
* QQ:5871029 Email:hel8@vip.qq.com
* @copyright Horleun (c)2010
* @author Horleun <Horleun@foxmail.com>
*/
$name=”Horleun”;
$sport=”篮球”;
?>—————————————————————–
<?php
/**
* QQ:5871029 Email:hel8@vip.qq.com
* @copyright Horleun (c)2010
* @author Horleun <Horleun@foxmail.com>
*/
function example() {
global $sport;
include ‘a_include.php’;
echo $name . “喜欢的运动是” . $sport .”!<br/>”;
}
example();echo $name . “喜欢的运动是” . $sport .”!<br/>”; //只定义了一个全局变量,所以只能显示一个!
include’no_such_file.php’;
echo”还好,我可以被输出!只是多个警告而已”;
require ‘no_such_file.php’;
echo’我没机会被输出了.’;
?>
include的应用,附带require的对比!
结果:
Horleun喜欢的运动是篮球!
Notice: Undefined variable: name in E:\sites\www\moving\non1146.php on line 14
喜欢的运动是篮球!Warning: include(no_such_file.php) [function.include]: failed to open stream: No such file or directory in E:\sites\www\moving\non1146.php on line 16
Warning: include() [function.include]: Failed opening ‘no_such_file.php’ for inclusion (include_path=’.;C:\php5\pear’) in E:\sites\www\moving\non1146.php on line 16
还好,我可以被输出!只是多个警告而已
Warning: require(no_such_file.php) [function.require]: failed to open stream: No such file or directory in E:\sites\www\moving\non1146.php on line 18Fatal error: require() [function.require]: Failed opening required ‘no_such_file.php’ (include_path=’.;C:\php5\pear’) in E:\sites\www\moving\non1146.php on line 18