Modifying capitalize( ) to take a reference parameter : strtoupper « String « PHP






Modifying capitalize( ) to take a reference parameter

 
<?php
function capitalize( &$str, $each=TRUE ){
{   
   $str = strtolower($str);
   if ($each === true) {

      $str = ucwords($str);
   } else {
      $str{0} = strtoupper($str{0});
   }
}
$str = "hEllo WoRld!";
capitalize( $str );
echo $str;
?>
  
  








Related examples in the same category

1.Changing case of strings
2.Converting Case
3.string strtoupper ( string str ) returns that string entirely in uppercase characters.
4.strtoupper(): Convert a string to uppercase
5.strtoupper.php
6.Using the word case functions