Posted By

dubogii on 05/17/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

IMPGTX


Automatic Copyright Year


 / Published in: PHP
 

URL: http://css-tricks.com/snippets/php/automatic-copyright-year/

  1. Current year only
  2.  
  3. &copy; <?php echo date("Y") ?>
  4.  
  5.  
  6. With start year
  7.  
  8. &copy; 2008-<?php echo date("Y") ?>
  9.  
  10.  
  11. Start date with error protection
  12.  
  13. <?php function auto_copyright($year = 'auto'){ ?>
  14. <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
  15. <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
  16. <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
  17. <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
  18. <?php } ?>
  19.  
  20.  
  21. Usage:
  22.  
  23. <?php auto_copyright(); // 2011?>
  24.  
  25. <?php auto_copyright('2010'); // 2010 - 2011 ?>

Report this snippet  

You need to login to post a comment.