I am having trouble finding a function that does exactly what I am looking for. Unfortunately, this feature is not compatible with UTF-8. This function is similar to the basic one ucwords, but it also has an uppercase character followed by one of the given characters (in my case, I need to use an uppercase letter for the character found after -).
Here is the function:
<?php
function my_ucwords($string)
{
$noletters='"([/-';
for($i=0; $i<strlen($noletters); $i++)
$string = str_replace($noletters[$i], $noletters[$i].' ', $string);
$string=ucwords($string);
for($i=0; $i<strlen($noletters); $i++)
$string = str_replace($noletters[$i].' ', $noletters[$i], $string);
return $string;
}
$title = 'ELVIS "THE KING" PRESLEY - (LET ME BE YOUR) TEDDY BEAR';
echo my_ucwords(strtolower($title));
?>
As soon as I add accents to my line, for example:
echo my_ucwords(strtolower( "saint-étienne" )) //return: Saint- instead of Saint-Étienne
Any idea? I know instead strlenI could use mb_strlen. But what about others?
Edit:
Recall that I need not only a simple one ucwordsthat works in UTF-8. I need uppercase to be applied to any character found after -.
.