你只需要將它包括在中間......就像那樣簡單。我會以一個例子向你展示。
<?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