Capitalize Words in PHP with custom delimitor
Posted
by Paulie
on Stack Overflow
See other posts from Stack Overflow
or by Paulie
Published on 2010-03-13T05:20:12Z
Indexed on
2010/03/13
5:25 UTC
Read the original article
Hit count: 272
Hey guys, 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. Greetz Paulie
© Stack Overflow or respective owner