您只需要将它包含在中间...就这么简单。我会用一个例子告诉你。
<?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>';
?>
尽管如您所说,如果有超过 1 个平台,您可能想学习使用PHP switch statment。
为了更好地理解,正如我所学到的:
当您使用 时include
,您实际上是将包含文件的代码放入您拥有的代码中*。假设 'testing.php' 有一个 echo echo "Hello world";
,那么上面的内容与此相同:
测试.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
?>
,并且您可以将多行作为一个行(您不需要在包含中使用花括号)。