note 28660 added to function.strtolower
| From: | bkimble at ebaseweb dot com | Date: | Mon, 20 Jan 2003 04:39:44 +0000 |
| Subject: | note 28660 added to function.strtolower | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42408@lists.php.net to get a copy of this message | ||
Heres a small function I wrote to stop people from submitting data that is ALL IN CAPS SO THEY CAN
GET MORE ATTENTION THAT THE REST OF THE USER SUBMITTED DATA on my website :) If you can make it
better, by all means do so. This function splits up words delimited by a space, and makes only the
first letter of each word capitalized. You can easily modify it so it's only the very first
word of the string. I've also added some exceptions so you don't make things like roman
numerals look like "Iii" or "Xcmii" or something.
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[0] = strtoupper($word[0]);
array_push($newwords, $word);
}
return join(" ", $newwords);
}
BK
--
http://www.php.net/manual/en/function.strtolower.php
http://master.php.net/manage/user-notes.php?action=edit+28660
http://master.php.net/manage/user-notes.php?action=delete+28660
http://master.php.net/manage/user-notes.php?action=reject+28660