note 13933 deleted from function.ucwords by victor

From: Date: Sat, 12 Jun 2004 21:04:03 +0000
Subject: note 13933 deleted from function.ucwords by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70984@lists.php.net to get a copy of this message
Note Submitter: paul@webkromatic.com ---- This is basically the same as Jim Thome's script above but it tests for numbers also. So if you have 3rd it won't end up 3Rd. function ucase_words($txt) { $i = 0; $txt = strtolower($txt); while ($i < strlen($txt)) { if (ord(substr($txt, $i, 1)) > 96 && ord(substr($txt, $i, 1)) < 123) // any lower case letter { if ($i == 0)//first letter should be upper case { $newtxt .= strtoupper(substr($txt, $i, 1)); } else {//check for preceding letter or number, so things like 3rd wont be 3Rd if ((ord(substr($txt, $i - 1, 1)) > 96 && ord(substr($txt, $i - 1 , 1)) < 123) || (ord(substr($txt, $i - 1, 1)) > 47 && ord(substr($txt, $i - 1, 1)) < 58)) { $newtxt .= substr($txt, $i, 1); } else { $newtxt .= strtoupper(substr($txt, $i, 1)); } } } else { $newtxt .= substr($txt, $i, 1); } $i++; } return($newtxt); } Paul Paul@webkromatic.com

« previous php.notes (#70984) next »