我在index.php页面顶部的第一个函数是:
<?php
$startYear = 2014;
$thisYear = date('Y');
if ($thisYear > $startYear) {
$copyright = "$startYear–$thisYear";
}
else {
$copyright = $startYear;
}
?>
我已将它包含在页脚中,如下所示:
<footer>
<p>© <?php echo $copyright; ?> MySite. All Rights Reserved</p>
</footer>
这完美无缺。
问题:我想将$ copyright函数放在名为functions.php的文件夹中名为myfunctions.php的文件中。请帮忙。感谢。
答案 0 :(得分:1)
稍微改为
<?PHP
function copyright(){
$startYear = 2014;
$thisYear = date('Y');
if ($thisYear > $startYear) {
$copyright = $startYear & $thisYear;
}
else {
$copyright = $startYear;
}
return $copyright;
}
?>
然后将整个函数添加到function.php
返回index.php并添加
<?PHP
include '\functions\myfunction.php';
?>
然后将其添加到页脚
<footer>
<p>© <?php echo copyright(); ?> MySite. All Rights Reserved</p>
</footer>
然后我会建议读这个 http://php.net/manual/en/function.include.php 和 http://php.net/manual/en/language.functions.php