Make a string’s first character uppercase

ucfirst — Make a string’s first character uppercase

example:

$coo= ‘clay desiccant!’;
$coo= ucfirst($desiccant); // Clay desiccant!

$bar = ‘CLAY DESICCANT!’;
$bar = ucfirst($bar); // CLAY DESICCANT!
$bar = ucfirst(strtolower($bar)); // Clay desiccant!

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);
}