note 51944 deleted from function.explode by bjori

From: Date: Mon, 25 Sep 2006 08:09:58 +0000
Subject: note 51944 deleted from function.explode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117590@lists.php.net to get a copy of this message
Note Submitter: JUSTIN -AT- LUTHRESEARCH -DOT- COM ---- A few changes to the proper case function above, 1. $reval was not declared (So it was giving off a notice) 2. If the first word was not a alpha character, it would not capitalze the second, for example "I Like PHP (it's Cool)" should be: "I Like PHP (It's Cool)" function properCase($strIn) { $retVal = null; $arrTmp = explode(" ", trim($strIn)); for($i=0; $i < count($arrTmp);$i++) { $firstLetter = substr($arrTmp[$i],0,1); if(isAlpha($firstLetter)){ $rest = substr($arrTmp[$i],1,strlen($arrTmp[$i])); $arrOut[$i] = strtoupper($firstLetter).strtolower($rest); }else{ $firstLetter = substr($arrTmp[$i],0,1); $SecondLetter = substr($arrTmp[$i],1,1); $rest = substr($arrTmp[$i],2,strlen($arrTmp[$i])); $arrOut[$i] = $firstLetter . strtoupper($SecondLetter).strtolower($rest); } } for($j=0; $j < count($arrOut); $j++) $retVal .= $arrOut[$j]." "; return trim($retVal); } function isAlpha($character) { $c = Ord($character); return ((($c >= 64) && ($c <= 90)) || (($c >= 97) && ($c <= 122))); }

« previous php.notes (#117590) next »