note 62243 deleted from function.ucfirst by nlopess
| From: | nlopess@php.net | Date: | Thu, 23 Feb 2006 09:39:44 +0000 |
| Subject: | note 62243 deleted from function.ucfirst by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-104285@lists.php.net to get a copy of this message | ||
Note Submitter: Blowfishie
----
This function does the same as ucfirst, but it preserves words that are in
uppercase. <?php // Function: string
kc_ucfirst ( string str ) // Keep Capitals - Uppercase First //
Make a string's first character uppercase and lowercase the rest, but
don't // touch any words that are already
uppercase. // // Works by splitting the string into an array of
words, then processing each // word in turn. When finished, uppercase the first
letter of the first entry function kc_ucfirst($Str) { $Array =
explode(" ", $Str); for ($i = 0; $i <
count($Array); $i++) { if ($Array[$i] == strtoupper($Array[$i]))
{ // Leave it alone - it's all uppercase } else
{ // Lowercase it $Array[$i] =
strtolower($Array[$i]); } }
// Now uppercase the first character of the first word
$Array[0][0] = strtoupper($Array[0][0]); return
(implode(" ", $Array)); } ?>