Learning PHP and MySQL

Example 05-04 Using the string capitalization functions

<?php
//  Capitalize  a  string 
function  capitalize(  $str  )
{
  
//  First,  convert  all  characters  to  lower  case
  
$str  =  strtolower($str);
  
//  Second,  convert  the  first  character  to  upper  case
  
$str{0}  =  strtoupper($str{0});
  echo  
$str;
}
capitalize
("hEllo  WoRld!"  );
?>

Posted by on 08/03 at 08:18 AM
  1. Please explain the curley braces meaning for $str{0}.
    I thought that to access each letter of $str as an array that
    $str[0] was appropriate.

    By the way I really like the book. Thanks, Ed

    Posted by  on  12/07  at  11:13 PM
  2. Page 1 of 1 pages

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

Previous entry: Example 05-03 Creating an md5 signature

<< Back to main