Learning PHP and MySQL
Example 05-05 Creating a capitalize function with a default parameter $each
<?php
// Capitalize a string or the first letter of each word
function capitalize( $str, $each=TRUE )
{
// First, convert all characters to lower case
$str = strtolower($str);
if ($each === TRUE) {
$str = ucwords ($str);
} else {
$str = strtoupper($str);
}
echo ("$str <br>");
}
capitalize("hEllo WoRld!");
echo ("Now do the same with the each parameter set to FALSE.<br>");
capitalize("hEllo WoRld!",FALSE);
?>
Posted by on 08/03 at 08:19 AM