B05a78cd33eb6b85c70d7f88d042d813

Could anyone make this smaller/simpler?

<?php
$time = time ();
$year= date("Y",$time);
if ($year == "2007") 
{
$year = "";
}
else {
$year = " - " . $year;
}
echo "Copyright &copy; 2007" . $year . " - All Rights Reserved - Design by scott2010_h";
?>

Refactorings

No refactoring yet !

D41d8cd98f00b204e9800998ecf8427e

JWvdV

October 8, 2007, October 08, 2007 04:09, permalink

2 ratings. Login to rate!
<?php
echo "Copyright &copy; 2007" . ((intval(date('Y')) != 2007)? : date('Y') : '') . " - All Rights Reserved - Design by scott2010_h";
?>
D8941b726b5851b8ebad73f458e58268

Mike Cochrane

October 8, 2007, October 08, 2007 05:13, permalink

2 ratings. Login to rate!

@JWvdV: Close, but you missed the ' - ' between then years. And the syntax error.

<?php
echo "Copyright &copy; 2007" . ((intval(date('Y')) != 2007) ? date(' - Y') : '') . " - All Rights Reserved - Design by scott2010_h";
?>
9513bc256e254c799454bb55832e8237

Emile

October 8, 2007, October 08, 2007 07:59, permalink

1 rating. Login to rate!

Easier to read.

<?php
printf("Copyright &copy; 2007 $s - All Rights Reserved - Design by scott2010_h", 
  (intval(date('Y')) != 2007) ? date(' - Y') : ''));
?>
9513bc256e254c799454bb55832e8237

Emile

October 8, 2007, October 08, 2007 13:05, permalink

No rating. Login to rate!

How foolish of me, forgot a ( here is the code that should work

<?php
printf("Copyright &copy; 2007 $s - All Rights Reserved - Design by scott2010_h", 
  ((intval(date('Y')) != 2007) ? date(' - Y') : ''));
?>
8bba46dba9043c254e6eef1aa664e6f0

EllisGL

October 8, 2007, October 08, 2007 13:45, permalink

1 rating. Login to rate!

Using single quotes is faster and comma on the echo speeds it up too.

echo 'Copyright &copy; 2007 ',((intval(date('Y')) != 2007) ? date(' - Y') : ''),' - All Rights Reserved - Design by scott2010_h';
E6615166d171570278017fd2652b846b

luck

October 8, 2007, October 08, 2007 15:46, permalink

No rating. Login to rate!
<?php 
$sCopyright = (intval(date('Y')) != 2007) ? '2007 - '.date(' - Y') : '2007';
print 'Copyright &copy; '.$sCopyright.'  - All Rights Reserved - Design by scott2010_h';
?>
918aabb05e77cfa8e40d2a76a5168326

travis

October 9, 2007, October 09, 2007 14:56, permalink

No rating. Login to rate!

Why even bother with concatenation server side?

Copyright &copy; 2007<?php
echo (intval(date('Y')) != 2007) ? date(' - Y') : '')
?> - All Rights Reserved - Design by scott2010_h
918aabb05e77cfa8e40d2a76a5168326

travis

October 9, 2007, October 09, 2007 14:57, permalink

No rating. Login to rate!

d'oh, i forgot a ';' :-(

D4aeba3e57cfa78a5dfd84a08849611e

Lokycss

October 9, 2007, October 09, 2007 18:12, permalink

No rating. Login to rate!

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 &copy; 2007<?php echo (intval(date('Y')) > 2007) ? date(' - Y') : ''); ?> - All Rights Reserved - Design by scott2010_h
B05a78cd33eb6b85c70d7f88d042d813

scott2010_h

October 10, 2007, October 10, 2007 04:12, permalink

2 ratings. Login to rate!

@ Lokycss there was an extra ")" near the end that cause the code not to work.

Copyright &copy; 2007<?php echo (intval(date('Y')) > 2007) ? date(' - Y') : ''; ?> - All Rights Reserved - Design by scott2010_h
28e65a85a625f7c0689bcf96ccf6043d

richardhealy

October 11, 2007, October 11, 2007 22:56, permalink

No rating. Login to rate!

I'm personally not a big fan of "echo"... "<?=" does the job with less brackets

Copyright &copy; 2007<?= intval(date('Y')) > 2007 ? date(' - Y') : ''; ?> - All Rights Reserved - Design by scott2010_h
28e65a85a625f7c0689bcf96ccf6043d

richardhealy

October 11, 2007, October 11, 2007 23:02, permalink

No rating. Login to rate!

Scrap the "bracket" comment... but I still stick to "<?=" :)-

D4aeba3e57cfa78a5dfd84a08849611e

Lokycss

October 12, 2007, October 12, 2007 22:14, permalink

No rating. Login to rate!

>> 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

28e65a85a625f7c0689bcf96ccf6043d

richardhealy

October 15, 2007, October 15, 2007 14:15, permalink

No rating. Login to rate!

Ah! I didn't know that! Cheers for the tip!

11d755068b875511c919413da0da7668

Urban

November 5, 2007, November 05, 2007 16:07, permalink

No rating. Login to rate!

Call date only once

Copyright &copy; 2007<?php if( ($Y = intval(date('Y'))) > 2007 ) echo " - $Y"; ?> - All Rights Reserved - Design by scott2010_h
11d755068b875511c919413da0da7668

Urban

November 6, 2007, November 06, 2007 08:49, permalink

No rating. Login to rate!

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 &copy; 2007<?php echo ( ($Y = intval(date('Y'))) > 2007 ) ? " - $Y" : ''; ?> - All Rights Reserved - Design by scott2010_h

Your refactoring





Format Copy from initial code

or Cancel