我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。

如何在php4或php5中自动更新年份?


当前回答

<?php echo date("Y"); ?>

其他回答

对于4位数表示:

<?php echo date('Y'); ?>

2位数表示:

<?php echo date('y'); ?>

查看php文档了解更多信息: https://secure.php.net/manual/en/function.date.php

顺便说一句……网站版权展示有几种合适的方式。有些人倾向于让事情变得多余,例如:版权©具有相同的含义。重要的版权部分包括:

**Symbol, Year, Author/Owner and Rights statement.** 

使用PHP + HTML:

<p id='copyright'>&copy; <?php echo date("Y"); ?> Company Name All Rights Reserved</p>

or

<p id='copyright'>&copy; <?php echo "2010-".date("Y"); ?> Company Name All Rights Reserved</p

如果你正在使用碳PHP API扩展DateTime,你可以很容易地实现:

<?php echo Carbon::now()->年;? >

我显示版权的方式,它会自动更新

<p class="text-muted credit">Copyright &copy;
    <?php
        $copyYear = 2017; // Set your website start date
        $curYear = date('Y'); // Keeps the second year updated
        echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');
    ?> 
</p>    

它将输出结果为

copyright @ 2017   //if $copyYear is 2017 
copyright @ 2017-201x    //if $copyYear is not equal to Current Year.

我是这么做的:

<?php echo date("d-m-Y") ?>

下面是对它功能的一些解释:

d = day
m = month
Y = year

Y表示四位数(如1990),Y表示两位数(如90)