PHP capitalize unicode string in brackets
I want to开发者_Python百科 capitalize every word even if it is in any kind of brackets () <> [] {}. It should capitalize unicode chars aswell.
For example:
ti si želva (čestitke)
should produce
Ti Si Želva (Čestitke)
I was using this function for very long time
function ucwords2($str)
{
$str = strtolower($str);
$str = preg_replace('/(?<![a-z]\')\b[a-z]/e', 'strtoupper(\'$0\')', $str);
return $str;
}
but now i need unicode support so it became unusable.
Thank you!
Here's what works for me:
$txt='ti si želva (čestitke)';
echo mb_convert_case($txt,MB_CASE_TITLE,'utf-8');
Got it?
I think the isLower() function is unicode-aware, so I think this would be a better way to check the characters. Don't know how you can do this into your regexp.
Try this:
function to_up($txt){
$up=mb_convert_case($txt,MB_CASE_TITLE,'utf-8');
return strtr($up,
array(
"'S"=>"'s",
"'D"=>"'d",
"'L"=>"'l"
)
);
}
$txt="john, it's all your fault!";
echo to_up($txt);
Note that you can add anything you want in the array...
精彩评论