How do I use PHP to get the current year?

后端 未结 26 2326
萌比男神i
萌比男神i 2020-12-04 04:31

I want to put a copyright notice in the footer of a web site, but I think it\'s incredibly tacky for the year to be outdated.

How would I make the year update automat

26条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 04:58

    My super lazy version of showing a copyright line, that automatically stays updated:

    ©  Me, Inc.
    

    This year (2008), it will say:

    © 2008 Me, Inc.

    Next year, it will say:

    © 2008-2009 Me, Inc.

    and forever stay updated with the current year.


    Or (PHP 5.3.0+) a compact way to do it using an anonymous function so you don't have variables leaking out and don't repeat code/constants:

    © 
     
    Me, Inc.
    

提交回复
热议问题