note 68340 added to function.strtoupper
| From: | Cory at osu1 dot php dot net | Date: | Mon, 24 Jul 2006 04:05:52 +0000 |
| Subject: | note 68340 added to function.strtoupper | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115069@lists.php.net to get a copy of this message | ||
This function converts any series of english words to Proper Casing. It also accounts for words
such as 'a' and 'the'. To change what words are ignored, just change the $noUp
array.
function strProper($str) {
$noUp =
array('a','an','of','the','are','at','in');
$str = trim($str);
$str = strtoupper($str[0]) . strtolower(substr($str, 1));
for($i=1; $i<strlen($str)-1; ++$i) {
if($str[$i]==' ') {
for($j=$i+1; $j<strlen($str) && $str[$j]!=' '; ++$j); //find next space
$size = $j-$i-1;
$shortWord = false;
if($size<=3) {
$theWord = substr($str,$i+1,$size);
for($j=0; $j<count($noUp) && !$shortWord; ++$j)
if($theWord==$noUp[$j])
$shortWord = true;
}
if( !$shortWord )
$str = substr($str, 0, $i+1) . strtoupper($str[$i+1]) . substr($str, $i+2);
}
$i+=$size;
}
return $str;
}
----
Server IP: 64.71.164.2
Probable Submitter: 69.254.56.235
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strtoupper.php
Edit -- http://master.php.net/note/edit/68340
Del: integrated -- http://master.php.net/note/delete/68340/integrated
Del: useless -- http://master.php.net/note/delete/68340/useless
Del: bad code -- http://master.php.net/note/delete/68340/bad+code
Del: spam -- http://master.php.net/note/delete/68340/spam
Del: non-english -- http://master.php.net/note/delete/68340/non-english
Del: in docs -- http://master.php.net/note/delete/68340/in+docs
Del: other reasons-- http://master.php.net/note/delete/68340
Reject -- http://master.php.net/note/reject/68340
Search -- http://master.php.net/manage/user-notes.php