Learning PHP and MySQL

Example 05-06 Modifying capitalize to take a reference parameter

<?php
function  capitalize(  &$str,  $each=true  )
{
  
//  First,  convert  all  characters  to  lower  case
  
$str  =  strtolower($str);
  if  (
$each  ===  true)  {
    $str  
=  ucwords($str);
  
}  else  {
    $str{0}  
=  strtoupper($str{0});
  
}
}
$str  
=  "hEllo  WoRld!"
capitalize(  &$str  ); 
echo  
$str;
?>

Posted by on 08/03 at 08:19 AM

Next entry: Example 05-08 Using the include function

Previous entry: Example 05-05 Creating a capitalize function with a default parameter $each

<< Back to main