Sunday, August 19, 2012

Uppercase for Person Names with and without Hyphen

function uclo($input) { 
  $pos = strpos($input, "-");
  if($pos === false) { return ucfirst(strtolower($input)); }
  else { $inputArr =explode("-", $input); 
  return ucfirst(strtolower($inputArr[0]))."-".ucfirst(strtolower($inputArr[1]));}
}
$firstName = "lAnce";
$lastName = "lincoln-Miller";
"Hello ".uclo($firstName)." ".uclo($lastName).".";

Hello Lance Lincoln-Miller.

No comments: