here is the best and possibly faster version that I just found out myself that supports multibyte utf-8 characters.
in my experience, regular expressions are slow in php, so there is a function based on string manipulation here.
function replace_first_word($text,$format='<big>{L}</big>'){
$words = explode(' ', $text);
foreach($words as &$word){
$first = substr($word, 0,1);
$word = substr($word,1);
$first = str_replace('{L}',$first,$format);
$word = $first.$word;
}
return implode(' ',$words);
}
also before php6 release, don't forget to set these 2 variables in php.ini to better support utf-8
mbstring.func_overload "7"
mbstring.internal_encoding "UTF-8"
source
share