這裏是PHP documentation smieat's comment採取了代碼。它應與土耳其點綴我的工作,你可以在以後的輔助功能添加更多的此類信件:
function strtolowertr($metin){
return mb_convert_case(str_replace('I','ı',$metin), MB_CASE_LOWER, "UTF-8");
}
function strtouppertr($metin){
return mb_convert_case(str_replace('i','İ',$metin), MB_CASE_UPPER, "UTF-8");
}
function ucfirsttr($metin) {
$metin = in_array(crc32($metin[0]),array(1309403428, -797999993, 957143474)) ? array(strtouppertr(substr($metin,0,2)),substr($metin,2)) : array(strtouppertr($metin[0]),substr($metin,1));
return $metin[0].$metin[1];
}
$s = "this is the, sample text.for replace the each words in, this'text sample' words";
echo preg_replace_callback('~\b\w+~u', function ($m) { return ucfirsttr($m[0]); }, $s);
// => This İs The, Sample Text.For Replace The Each Words İn, This'Text Sample' Words
見IDEONE demo
間接地希望每個字用大寫字母開頭..:d –
它不在「文本樣本」字符串上工作。 –
我還有編碼問題,我添加了鏈接。我怎樣才能通過這些問題 –