note 12949 deleted from function.ucwords by victor
| From: | victor@php.net | Date: | Sat, 12 Jun 2004 21:03:21 +0000 |
| Subject: | note 12949 deleted from function.ucwords by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70983@lists.php.net to get a copy of this message | ||
Note Submitter: jthome@fcgov.com
----
This function will change the first letter of any words to uppercase. Any letter that doesn't
have another letter in front of it is considered a word, which eliminates the need to care about a
delimiter. (I avoid regular expressions except when I have to deal with large amounts of text.)
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)//any first letter should be upper case
{
$newtxt .= strtoupper(substr($txt, $i, 1));
} else {//check for preceding letter
if (ord(substr($txt, $i - 1, 1)) > 96 && ord(substr($txt, $i - 1 , 1)) < 123)
{
$newtxt .= substr($txt, $i, 1);
} else {
$newtxt .= strtoupper(substr($txt, $i, 1));
}
}
} else {
$newtxt .= substr($txt, $i, 1);
}
$i++;
}
return($newtxt);
}
Hope this helps someone.
Jim Thome
jthome@fcgov.com
http://fcgov.com