Automatic Copyright Year


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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 ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.