Dec
27
2010

Caps Control with PHP

When dealing with user input, you will often come across people who keep their Caps Lock key permanently enabled, which can make reading what they write difficult on the eye. It also looks like they are shouting. To solve the problem, we can writhe a simple PHP script which with different modes for case manipulation.

function Convert($text,$mode="")
{
if($mode == "ac")
return strtoupper($text);
else if($mode == "al")
return strtolower($text);
else if($mode == "cew")
{
$text = explode(" ",$text);
foreach($text as $t)
$temp .= ucfirst(strtolower($t))." ";
return $temp;
}
else if($mode = "ces")
{
$text = explode(".",$text);
foreach($text as $t)
$temp .= ucfirst(ltrim(strtolower($t))).".";
return $temp;
}

return $text;
}

Here what it does:
$text is the must be a string
$mode is the mode of capitalization, by default it is set to “” and if you didn’t give it a value then the script will just return the $text unchanged.
Modes:
“ac” means “all capitalized” capitalizes every letter.
“al” means “all lower” converts all the letters to lower case.
“cew” means “capitalize every word”, each new word is being capitalized.
“ces” means “capitalize each sentence”, each new sentence is going to be capitalized.
Usage:
Convert(“XAXAXA I AM SHOUTINT”,”cew”)
Now the guy is not shouting.

Enter Your Mail Address

Related And Similar Posts

1 Comment + Add Comment

Leave a comment

*

Facebook Fans

Share Me With Google Plus!

Popular Posts

Social Bookmarking sites list 2012 - New and fresh bookmarking sites
Comments93
Bulgarian proxy or how to open arenabg and zamunda
Comments65
+ 150 New Free Directory Sites List 2012 - Sorted by Page Rank
Comments22
Scrapebox crack free download ?
Comments19
Great List With Google Plus / FB likes/ tweets exchange sites - Hot Topic
Comments16
How to make World Of Warcraft Cataclysm Server
Comments10
The Best Bulgarian Torrents - Listing
Comments9
500 Free Directory List 2011 !
Comments9
Free RSS Directory List Where To Submit Your Site
Comments9
Guest Blogs List and Useful Information
Comments8

Recent Posts

Calendar

December 2010
M T W T F S S
    Jan »
 12345
6789101112
13141516171819
20212223242526
2728293031