<?php
$time = time ();
$year= date("Y",$time);
if ($year == "2007")
{
$year = "";
}
else {
$year = " - " . $year;
}
echo "Copyright © 2007" . $year . " - All Rights Reserved - Design by scott2010_h";
?>
Refactorings
No refactoring yet !
JWvdV
October 8, 2007, October 08, 2007 04:09, permalink
<?php
echo "Copyright © 2007" . ((intval(date('Y')) != 2007)? : date('Y') : '') . " - All Rights Reserved - Design by scott2010_h";
?>
Mike Cochrane
October 8, 2007, October 08, 2007 05:13, permalink
@JWvdV: Close, but you missed the ' - ' between then years. And the syntax error.
<?php
echo "Copyright © 2007" . ((intval(date('Y')) != 2007) ? date(' - Y') : '') . " - All Rights Reserved - Design by scott2010_h";
?>
Emile
October 8, 2007, October 08, 2007 07:59, permalink
Easier to read.
<?php
printf("Copyright © 2007 $s - All Rights Reserved - Design by scott2010_h",
(intval(date('Y')) != 2007) ? date(' - Y') : ''));
?>
Emile
October 8, 2007, October 08, 2007 13:05, permalink
How foolish of me, forgot a ( here is the code that should work
<?php
printf("Copyright © 2007 $s - All Rights Reserved - Design by scott2010_h",
((intval(date('Y')) != 2007) ? date(' - Y') : ''));
?>
EllisGL
October 8, 2007, October 08, 2007 13:45, permalink
Using single quotes is faster and comma on the echo speeds it up too.
echo 'Copyright © 2007 ',((intval(date('Y')) != 2007) ? date(' - Y') : ''),' - All Rights Reserved - Design by scott2010_h';
luck
October 8, 2007, October 08, 2007 15:46, permalink
<?php
$sCopyright = (intval(date('Y')) != 2007) ? '2007 - '.date(' - Y') : '2007';
print 'Copyright © '.$sCopyright.' - All Rights Reserved - Design by scott2010_h';
?>
travis
October 9, 2007, October 09, 2007 14:56, permalink
Why even bother with concatenation server side?
Copyright © 2007<?php
echo (intval(date('Y')) != 2007) ? date(' - Y') : '')
?> - All Rights Reserved - Design by scott2010_h
Lokycss
October 9, 2007, October 09, 2007 18:12, permalink
Follow "Travis" code:
Checking if the date is greater than 2007; maybe the configuration of server is wrong.
e.g: 2007 - 2003
P.S: sorry for my english.
Copyright © 2007<?php echo (intval(date('Y')) > 2007) ? date(' - Y') : ''); ?> - All Rights Reserved - Design by scott2010_h
scott2010_h
October 10, 2007, October 10, 2007 04:12, permalink
@ Lokycss there was an extra ")" near the end that cause the code not to work.
Copyright © 2007<?php echo (intval(date('Y')) > 2007) ? date(' - Y') : ''; ?> - All Rights Reserved - Design by scott2010_h
richardhealy
October 11, 2007, October 11, 2007 22:56, permalink
I'm personally not a big fan of "echo"... "<?=" does the job with less brackets
Copyright © 2007<?= intval(date('Y')) > 2007 ? date(' - Y') : ''; ?> - All Rights Reserved - Design by scott2010_h
richardhealy
October 11, 2007, October 11, 2007 23:02, permalink
Scrap the "bracket" comment... but I still stick to "<?=" :)-
Lokycss
October 12, 2007, October 12, 2007 22:14, permalink
>> I'm personally not a big fan of "echo"... "<?=" does the job with less brackets
Be careful, only can use the "short tags" when the server are configured specifically for that (short_open_tag is on).
See the directive "short_open_tag" on http://www.php.net/manual/en/ini.core.php
richardhealy
October 15, 2007, October 15, 2007 14:15, permalink
Ah! I didn't know that! Cheers for the tip!
Urban
November 5, 2007, November 05, 2007 16:07, permalink
Call date only once
Copyright © 2007<?php if( ($Y = intval(date('Y'))) > 2007 ) echo " - $Y"; ?> - All Rights Reserved - Design by scott2010_h
Urban
November 6, 2007, November 06, 2007 08:49, permalink
This is better for time:
IF and vars take about 40 microsec, IF and 2 data() calls take about 55 microsec and this one take about 33 microsecs on execution.
Copyright © 2007<?php echo ( ($Y = intval(date('Y'))) > 2007 ) ? " - $Y" : ''; ?> - All Rights Reserved - Design by scott2010_h
Could anyone make this smaller/simpler?