NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   Auto Update Copyright [PHP] (http://www.namepros.com/code/273451-auto-update-copyright-php.html)

suhithar 12-26-2006 12:01 PM

Auto Update Copyright [PHP]
 
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

cyberoptik 12-26-2006 12:06 PM

Very useful :) thanks.

suhithar 12-26-2006 12:10 PM

Glad I could help :D

RickM 12-26-2006 01:10 PM

Just a note, you don't need brackets round echo tags in php4+

e.g:

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

Dan 12-26-2006 01:40 PM

PHP Code:
<?php echo "Copyright &copy; 1950 - " . date("Y"); ?>

suhithar 12-26-2006 01:45 PM

Thanks for the help guys!

Matthew. 12-26-2006 02:06 PM

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 Code:
echo 'Copyright &copy; 1950 - ' . date('Y');

...would be better as we do not variables names to be expanded. Now that's being picky lol

Dan 12-26-2006 02:53 PM

PHP Code:
echo'Copyright &copy; 1950 - '.date('Y');
Those extra 3 bytes were killer.

Matthew. 12-26-2006 03:04 PM

touché Dan. :hehe:

jdk 12-26-2006 10:31 PM

Why not just do?

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

Matthew. 12-27-2006 04:54 AM

Originally Posted by jdk
Why not just do?

PHP Code:
Copyright &copy; 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.

jerometan 12-28-2006 09:58 AM

If those bytes really matter :P, this will work for PHP 5+ :

PHP Code:
Copyright &copy; 1995 - <?=date("Y");?>

Matthew. 12-28-2006 11:32 AM

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 Code:
Copyright &copy; 1995 - <?=date("Y")?>


The closing tag (?>) also adds a semi colon, so you don't have to :D

Stitch 01-20-2007 03:22 PM

wow LOL this site has some picky people ;) lol

shockie 01-20-2007 03:57 PM

Originally Posted by . Adam .
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.


All times are GMT -7. The time now is 02:03 PM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0