Automatic Copyright Year in PHP

Snippet

To add a copyright year in PHP that updates with the current year, you can use the code below:

downloadcopy
© <?php echo date("Y"); ?>

With start year:

downloadcopy
© 2016-<?php echo date("Y"); ?>

Smart function:

downloadcopy
<?php
function autoCopyright($year = false){ 
   if($year == false) $year = date('Y');
   if(intval($year) == date('Y')) return intval($year); 
   if(intval($year) < date('Y')) return intval($year) . ' - ' . date('Y');
   if(intval($year) > date('Y')) return date('Y');
}
?>

© <?=autoCopyright(); // current year ?>
© <?=autoCopyright(2017); // 2017-{current year} ?>