Good day,
I had trouble finding a function that does exactly what I am looking for. Unfortunatly, this function isn't UTF-8 Compatible. This functions is like a basic ucwords
but it also do the uppercase on a character followed by one of the given characters found (in my case I need to apply an uppercase on the character found after a -
Here is the function:
<?php
function my_ucwords($string)
{
$noletters='"([/-'; //add more if u need to
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 string eg:
echo my_ucwords(strtolower( "saint-étienne" )) //return: Saint- instead of Saint-Étienne
Any idea guys? I know instead of the strlen
I could use mb_strlen
. But what about the others?
Edit:
Just a reminder guys that I do not only need a simple ucwords
working in UTF-8
. I need it to apply the uppercase on any character found after a -
I'm still trying to figure out on my side too.