PHP ʖ²ἯTH
º/A
Ղ 12. w³̿ؖƼ/TD
include()
The include() ӯ¾䰼(²¢ԋАָ¶¨΄¼þ¡£
vars.php ?php $color = 'green'; $fruit = 'apple';? test.php ?php echo "A $color $fruit"; // A include 'vars.php'; echo "A $color $fruit"; // A green apple?
?php function foo() {global $color; include 'vars.php'; echo "A $color $fruit";} /* vars.php is in the scope of foo() so * * $fruit is NOT available outside of this * * scope. $color is because we declared it * * as global. */ foo(); // A green apple echo "A $color $fruit"; // A green?
¾¯¸漯B
Windows °汾µĠPHP Ԛ 4.3 °斮ǰ²»֧³ָú¯ʽµĔ¶³̎ļþ·Îʣ¬¼´ʹ allow_url_fopen ѡϮґ±»¼¤»
?php /* This example assumes that www.example.com is configured to parse .php * * files and not .txt files. Also, 'Works' here means that the variables * * $foo and $bar are available within the included file. */ // Won't work; file.txt wasn't handled by www.example.com as PHP include 'http://www.example.com/file.txt?foo=1 bar=2'; // Won't work; looks for a file named 'file.php?foo=1 bar=2' on the // local filesystem. include 'file.php?foo=1 bar=2'; // Works. include 'http://www.example.com/file.php?foo=1 bar=2'; $foo = 1; $bar = 2; include 'file.txt'; // Works. include 'file.php'; // Works.?
=ד 12-6. include() ӫ̵¼þӯ¾䗩
?php // This is WRONG and will not work as desired. if ($condition) include $file; else include $other; // This is CORRECT. if ($condition) {include $file;} else {include $other;}?
=ד 12-7. include() º͠ return() ӯ¾伯B
return.php ?php $var = 'PHP'; return $var;? noreturn.php ?php $var = 'PHP';? testreturns.php ?php $foo = include 'return.php'; echo $foo; // prints 'PHP' $bar = include 'noreturn.php'; echo $bar; // prints 1?
º/A
ưµ㼯A
require()
ɏһ¼¶
require_once()