Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

PHP - copyright year

0 votes
8 views
added May 31 in PHP by LC Marshal First Warrant Officer (9,130 points)
//current year only
&copy; <?php echo date("Y"); ?>

// with a start year
&copy; 2001-<?php echo date("Y"); ?>

//1. 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 } ?>

//2. Usage
<?php auto_copyright(); // 2011?>
<?php auto_copyright("2010");  // 2010 - 2017 ?>

Please log in or register to response this reference.

lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...