0

Here's my copyright as of right now:

<i>Example.com</i> &copy; 2013 - <?php echo date('Y'); ?>

this is okay next year because it will read:

Example.com © 2013 - 2014

but this year it says: © 2013-2013

How can I make it © 2013 and auto switch to © 2013-2014 next year, without having to come back and change it by hand?

4

7 回答 7

7

It should be

<i>Example.com</i> &copy; 2013 <?php (date('Y') !== "2013") echo "- " . date('Y')); ?>
于 2013-08-08T22:39:42.377 回答
3
$startYear = 2013; 
$currentYear = date('Y');
echo $startYear;
if ($startYear != $currentYear) {
    echo '-' . $currentYear;
}

That handles the years part of the Copyright message, just enter the other formatting around the output as you require.

(I've aimed for the longer but more readable approach, take your pick)

于 2013-08-08T22:37:09.583 回答
2

You can use the php code to get dynamic year as well as the domain of your hosting server

<?php echo "&copy; ". date(Y)." ".$_SERVER['HTTP_HOST'] ;?>
于 2017-07-24T08:19:46.397 回答
1
<i>Example.com</i> &copy; 2013 <?=(date('Y')>2013?' - '.date('Y'):'')?>
于 2013-08-08T22:35:53.333 回答
1
<?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 } ?>
//where you want to use just paste it:
<?php auto_copyright('2010'); ?>//2010-2015
<?php auto_copyright(); ?>//current year i.e:2015
于 2015-08-04T06:14:56.377 回答
0
<i>Example.com</i> &copy; <?php echo (date('Y')==2018)?(date('Y')):'2018 - '.date('Y'); ?>
于 2018-06-23T07:09:51.930 回答
0
<i>Example.com</i> &copy; <?php if (date('Y') != '2013') { echo '2013 - ' } echo date('Y'); ?>
于 2021-06-29T15:12:03.533 回答