我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
当前回答
http://us2.php.net/date
echo date('Y');
其他回答
全年使用:
<?php
echo $curr_year = date('Y'); // it will display full year ex. 2017
?>
或者只得到两位年份,就像这样:
<?php
echo $curr_year = date('y'); // it will display short 2 digit year ex. 17
?>
$dateYear = date('Y');
echo "Current Year: $dateYear";
本年:2022年
$dateYear = date('y');
echo $dateYear;
22
顺便说一句……网站版权展示有几种合适的方式。有些人倾向于让事情变得多余,例如:版权©具有相同的含义。重要的版权部分包括:
**Symbol, Year, Author/Owner and Rights statement.**
使用PHP + HTML:
<p id='copyright'>© <?php echo date("Y"); ?> Company Name All Rights Reserved</p>
or
<p id='copyright'>© <?php echo "2010-".date("Y"); ?> Company Name All Rights Reserved</p
echo date('Y')给你当前年份,这将自动更新,因为date()给我们当前日期。
对于4位数表示:
<?php echo date('Y'); ?>
2位数表示:
<?php echo date('y'); ?>
查看php文档了解更多信息: https://secure.php.net/manual/en/function.date.php