- Michael Barton |
- PHP, Programming Languages, Tips |
- April 18th, 2009
I still see on a lot of sites the copyright date being outdated. Shoot, it was even outdated on mine. How embarrassing. Easy fix though. Something I do at work all the time, but since I’m not getting paid for this site, it wasn’t done.
Now, let’s forget the past and move onto the future.
The solution (in PHP):
1 2 3 4 | function copyright_year($year = '2009', $sep = '-') { $current_year = date('Y'); return ($year == $current_year) ? $year : $year . $sep . $current_year; } |
OR, for those that need more lines (I do too. I like to be able to READ my code):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function copyright_year($year = '2009', $sep = '-') { <span id="more-79"></span> $current_year = date('Y'); // compare year that is passed in with current year if($year == $current_year) { return $year; } // I hate writing the word "else" return $year . $sep . $current_year; } |
I’ve also made it easy for you to download the source code, just in case you like things REALLY simple! I do, don’t be shy.
