这篇文章主要为大家详细介绍了PHP利用include和require的区别用法,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!
nclude()代码如下:
<?php
/* 四海网 www.q1010.com */
$color = 'green';
$fruit = 'apple';
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
echo "A $color $fruit"; // A
include 'vars.php';
echo "A $color $fruit"; // A green apple
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
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
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
/* 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.
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
// 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;
}
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
$var = 'PHP';
return $var;
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
$var = 'PHP';
?>
代码如下:
<?php
/* 四海网 www.q1010.com */
$foo = include 'return.php';
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
?>
本文来自:http://www.q1010.com/173/15385-0.html
注:关于PHP利用include和require的区别用法的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。