I need a method to capitalize every first letter of a word. This is what i got so far and it is working for almost every string...but it fails on this one "WELLNESS & RENOMME".
// method in stringModify Class
function capitalizeWords($words, $charList) {
$capitalizeNext = true;
for ($i = 0, $max = strlen($words); $i < $max; $i++) {
if (strpos($charList, $words[$i]) !== false) {
$`capitalizeNext` = true;
} else if ($capitalizeNext) {
$capitalizeNext = false;
$words[$i] = strtoupper($words[$i]);
}
}
return $words;
}
// Calling method
$stringModify->capitalizeWords("WELLNESS & RENOMME", " -&");
I hope someone can help me out...i tried for 1,5 hours now and don't have a clue. Thanks in advance for any tips or hints.
edit
ucwords() uses " " as delimitor and i want to use "-" for example too.
edit
thanks to you all for you solutions. i will go to bed now, its 7 in the morning here. :D i will see which solution i like best when i wake up and then tell you which one i choosed.
edit
it seems like all the functions are returning "wellness &Amp; Renomme" or "wellness & Renomme". is it possible that something in my php.ini is messed up?