Created
November 16, 2015 16:03
-
-
Save dsmy/ed57c5e8ee3b5dd5a80c to your computer and use it in GitHub Desktop.
Auto update copyright in footer with error protection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Referenced from https://css-tricks.com/snippets/php/automatic-copyright-year/--> | |
<!--Start date with error protection--> | |
<?php function auto_copyright($year = 'auto'){ ?> | |
<?php if(intval($year) == 'auto'){ $year = date('Y'); } ?> | |
<?php if(intval($year) == date('Y')){ echo intval($year); } ?> | |
<?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?> | |
<?php if(intval($year) > date('Y')){ echo date('Y'); } ?> | |
<?php } ?> | |
<!--Usage--> | |
<?php auto_copyright('2009'); // 2009 - 2015 ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment