29th October 2012 - 2 minutes read time
When posting happy birthday messages to developers over social media I like to write it in code, just to be geeky. The following code will print the happy birthday song using PHP.
<?php
$string = '';
for ($i = 0; $i < 4; $i++) {
$string .= "Happy birthday ";
if ($i != 2) {
$string .= "to you!\n";
} else {
$string .= "dear %s!\n";
}
}
print sprintf($string, 'name');
This can be easily personalised by just changing the second parameter in the sprintf() function.