note 20949 deleted from function.strtoupper by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 12 Jan 2004 23:05:31 +0000 |
| Subject: | note 20949 deleted from function.strtoupper by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63377@lists.php.net to get a copy of this message | ||
Note Submitter: mike@mikereid.net
----
Here is a nice function I wrote to convert a string into title case.
i.e.
from => "the grapes of wrath"
to => "The Grapes Of Wrath"
Here is my function:
==========================================
function strtotitle($strtochange){
$strtochange = strtolower($strtochange);
$string_array = explode(" ",$strtochange);
$fixed_str = "";
foreach ($string_array as $part){
$fixed_str .= strtoupper(substr("$part",0,1));
$fixed_str .= substr("$part",1,strlen($part));
$fixed_str .= " ";
}
return rtrim($fixed_str);
}
$title_str = strtotitle($STRING_TO_CHANGE);
==========================================
I hope this helps someone... I know it worked out perfect for me!
Enjoy!