Auto Update Copyright [PHP]

SpaceshipSpaceship
Watch

Ryder

Established Member
Impact
5
Have you ever made a site and always had to change the copyright? Well you came to the right place!

Here is a PHP code which will automatically update to the current year :D

<?PHP $date = date('Y'); echo ("Copyrighted 1950 - $date"); ?>

What that script does it, it outputs the current date!

More tutorials coming soon at:
http://www.netsuhi.com
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Very useful :) thanks.
 
0
•••
Glad I could help :D
 
0
•••
Just a note, you don't need brackets round echo tags in php4+

e.g:

PHP:
<?php 
$date=date('Y');
echo"Copyrighted 1950 - $date";
?>
 
0
•••
PHP:
<?php echo "Copyright © 1950 - " . date("Y"); ?>
 
0
•••
Thanks for the help guys!
 
0
•••
rmwebs, i don't think it is since php4. echo is and also has been a language construct which do not require parenthesis. To my knowledge is it not version dependent.

Dan, now you're just being picky lol!

technically....
PHP:
echo 'Copyright © 1950 - ' . date('Y');
...would be better as we do not variables names to be expanded. Now that's being picky lol
 
0
•••
PHP:
echo'Copyright © 1950 - '.date('Y');
Those extra 3 bytes were killer.
 
0
•••
touché Dan. :hehe:
 
0
•••
Why not just do?

PHP:
Copyright © 1995 - <?php echo date("Y");?>
 
0
•••
jdk said:
Why not just do?

PHP:
Copyright © 1995 - <?php echo date("Y");?>

I think it was assumed that the lines previous to this one would have been in php hence you would not bother with the advantages of breaking out of php to output and simply echo it as it is only 1 line.
 
0
•••
If those bytes really matter :P, this will work for PHP 5+ :

PHP:
Copyright © 1995 - <?=date("Y");?>
 
0
•••
Let us think of compatibility jromentan! What if short_open_tag is disabled lol.

Anyway, that will work for all versions of php, not just php5+. Also it can be beaten lol! Remember just how important those bytes ares ;)

PHP:
 Copyright © 1995 - <?=date("Y")?>

The closing tag (?>) also adds a semi colon, so you don't have to :D
 
0
•••
wow LOL this site has some picky people ;) lol
 
0
•••
. Adam . said:
wow LOL this site has some picky people ;) lol
i know eh?... and i thought the cost of bandwidth was going down!! good job though guys; striving for excellence is enviable.
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy — Payment Flexibility
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back