note 32844 added to function.ucfirst
| From: | bkimble at ebaseweb dot com | Date: | Sun, 08 Jun 2003 22:02:12 +0000 |
| Subject: | note 32844 added to function.ucfirst | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50005@lists.php.net to get a copy of this message | ||
Here is a handy function that makes the first letter of everything in a sentence upercase. I used it
to deal with titles of events posted on my website ... I've added exceptions for uppercase
words and lowercase words so roman numeral "IV" doesn't get printed as "iv"
and words like "a" and "the" and "of" stay lowercase.
function RemoveShouting($string)
{
$lower_exceptions = array(
"to" => "1", "a" => "1", "the" =>
"1", "of" => "1"
);
$higher_exceptions = array(
"I" => "1", "II" => "1", "III" =>
"1", "IV" => "1",
"V" => "1", "VI" => "1", "VII" =>
"1", "VIII" => "1",
"XI" => "1", "X" => "1"
);
$words = split(" ", $string);
$newwords = array();
foreach ($words as $word)
{
if (!$higher_exceptions[$word])
$word = strtolower($word);
if (!$lower_exceptions[$word])
$word = ucfirst($word);
array_push($newwords, $word);
}
return join(" ", $newwords);
}
----
Manual Page -- http://www.php.net/manual/en/function.ucfirst.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32844
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32844&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32844&report=yes