I'm confused at what exactly you're trying to do. PHP already has a ucwords()
function that can do this and I don't see any difference in what you're doing... If you're capitalizing the first letter of each word, do delimiters make any difference? Does it matter at all that there's a '&' between the two words?
Edit: I think I understand now. I assume the only problem you're having is that you can't tell it's uppercasing the text because it's already all uppercased, all you need to do is lowercase it first. I also changed it to completely get rid of the 'next character' thing, it was unnecessary. If you find a match, just change the next character to uppercase. Try this:
// method in stringModify Class
function capitalizeWords($words, $charList) {
$words = strtolower($words); // lowercase everything that isn't capitalized
for ($i = 0; $i < strlen($words); $i++) {
if (strpos($charList, $words[$i]) !== false) $words[$i+1] = strtoupper($words[$i+1]);
}
return $words;
}
// Calling method
$stringModify->capitalizeWords("WELLNESS & RENOMME", " -&");
animuson
2010-03-13 05:25:50