Cleaner Google Homepage + Cookie Monster Doodle

November 5, 2009 · Posted in Web Stuff · 2 Comments 

Perhaps I have been slow on the uptake here, but the Google search homepage is elegantly simplified, until you move your mouse.

This morning when I arrived I saw Cookie Monster staring back at me, but also nothing other than the Google search input box:

google homepage less busyWell I say it is less busy but Cookie Monster is certainly getting busy chewing his way through Google. Then once you move your mouse some Javascript fades in the missing clutter on the Google homepage that we have grown used to:

busy google homepage with Cookie MonsterWhat do you think of the cleaner Google homepage? I love it (I am assuming when the monster is gone it will remain like this).

I took a look around and it seems to only give me the cleaner Google homepage in Firefox on google.com and google.co.za but not google.co.uk. Other browsers are displaying as they always have (except of course for Cookie Monster). The code doing the reveal in Firefox is using an event in the <html> tag:
<html onmousemove="google&&google.fade&&google.fade()">

For the Google story on the Week’s Sesame Street Google Doodles, and all the Doodles in one place.

Short PHP IF-Else Statements (Shorthand IF)

November 4, 2009 · Posted in PHP · 1 Comment 

Funny thing is I have been working in PHP for years, but only with the prevalence of CMS’s have I required short code for PHP, I have always just typed things out in full. These shortened PHP conditional statements are called ternary operators, and I find them most useful when popping code into a CMS code block, otherwise I generally code stuff in full for legibility.

If you look at the PHP manual they give you the following alternative syntax which is really not that compact:

<?php
## all examples start with $x having a value of 3 ##
if ($x == 3):
echo "X is equal to 3";
else:
echo "X is not equal to 3";
endif;
?>

And that if and elseif … endif structure is fine, but what about one line alternative code for a PHP if statement:

<?php if ($x == 3): echo "X is equal to 3"; else: echo "X is not equal to 3"; endif; ?>

But still this is not that efficient, the following two versions give nice compact code the first for just printing the value:

<?php echo ($x == 3)? "X is equal to 3" : "X is not equal to 3"; ?>

and the second allocates the string value to $y, dependent on the short if statement, and then prints:

<?php $y = ($x == 3)? "X is equal to 3" : "X is not equal to 3" ; ?>
<?php echo $y ; ?>

And of course if all you want to do is print one thing’s value dependant on its not being blank or zero:

<?php echo ($z)? $z : "" ; ?>

Nice short if statement, have I missed anything?

The PHP manual does have a couple of points if you scroll down on this page. The most notable is “avoid “stacking” ternary expressions”; if you want your code to be readable dont nest ternary conditional statements.