你只需要将它包括在中间......就像那样简单。我会以一个例子向你展示。
<?php
echo "It's a nice day to send an email OR an sms.<br>";
$Platform = "mobile";
if ($Platform == "mobile")
{
include 'testing.php';
}
else
{
include 'whatever.php';
}
echo "The message was sent! Now I will print from 0 to 100:<br>";
for ($i = 0; $i<= 100; $i++)
echo $i . '<br>';
?>
Althought,如果有超过1个平台如你所说,你可能想学习使用PHP switch statment。
为了更好的理解和我学会了:
当您使用include
,你literately把包含文件的代码在你的代码*。说 'testing.php' 具有确实echo "Hello world";
回波,则上述是相同的,因为这:
testing.php
<?php
echo "Hello world";
?>
的index.php(或任何名称):
<?php
echo "It's a nice day to send an email OR an sms.<br>";
$Platform = "mobile";
if ($Platform == "mobile")
{
echo "Hello world";
}
else
{
include 'whatever.php';
}
echo "The message was sent! Now I will print from 0 to 100:<br>";
for ($i = 0; $i<= 100; $i++)
echo $i . '<br>';
?>
*有几个例外:您需要将PHP标签放入包含文件<?php
?>
中,并且可以将多行代码作为一个代理(您不需要include中的大括号)。
回应来自该文件的'testing.php'内的任何内容。 – samayo 2013-05-06 16:17:42
你是什么意思?如果我想通过传递参数来调用函数? – donparalias 2013-05-06 16:20:25
'include()'运行一个包含的php,然后父php继续 – 2013-05-06 16:22:04