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.
Comments
Alternative:
function singHappyBirthday($nm) { for ($i = 0; $i < 4; $i++) { printf("Happy birthday %s!\n", (2 === $i) ? "dear {$nm}" : "to you"); } } singHappyBirthday('name');
function singHappyBirthday($nm, $i = 0) { printf("Happy birthday %s!\n", (2 === $i) ? "dear {$nm}" : "to you"); return $i === 3 || singHappyBirthday($nm, ++$i); } singHappyBirthday('name');
Happiest wishes to you on this special day!!!
Thank for the tips
<?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');