我得到的數據是這樣的:「ӘІҢҒҮКҚӨҺ」。 將此數據轉換爲此:d398d086d2a2d292d2aed2b0d29ad3a8d2ba 然後爲* .rtf格式添加「\'」:\'d3 \'8d \ '86 \'2a \'d2 \'2d \'ae \'2b \'d2 \廣告\ 'A8 \' 2Bstr_replace給出錯誤結果
,然後我得somethingl IKE在此:\ u1179 \ '3F \ U1240 \' 3F \ u1186 \'3F ...
但str_replace函數只替換斜槓Q_Q。
有什麼建議嗎?
這裏是全碼:
<?
function strToHex($string)
{
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function extra($txt) {
$output_arr = array (
//
"\\u1179\\'3f","\\u1240\\'3f","\\u1186\\'3f","\\u1170\\'3f","\\u1198\\'3f","\\u1200\\'3f","\\u1178\\'3f","\\u1256\\'3f","\\u1210\\'3f"
);
$input_arr = array (
//
"\\'d3\\'98","\\'d0\\'86","\\'d2\\'a2","\\'d2\\'92","\\'d2\\'ae","\\'d2\\'b0","\\'d2\\'9a","\\'d3\\'a8","\\'d2\\'ba"
);
echo "<br>";
echo "data: ".$txt."<br>";
$txt = strtohex($txt);
echo "hex: ".$txt."<br>";
for ($ii=0; $ii < strlen($txt); $ii++) {
//
if (strlen($tm1)<2) {
//
$tm1.=substr($txt,$ii,1);
}
else
{
//
$ret.="\\'".$tm1;
$tm1='';
}
}
echo "RET:[".$ret."]<br>";
$ret = str_replace($input_arr,$output_arr,$ret);
echo "RETREP:[".$ret."]<br>";
return $ret;
}
extra("ӘІҢҒҮҰҚӨҺ");
?>
檢查http://stackoverflow.com/questions/1451144/php-multi-byte-str-replace – thwd
@湯姆,沒有。這不適合我,這些信件是從MySQL數據庫中獲取的。他們在unicode(utf8)中。所以我試圖比較hexed值並用rtf spec格式替換它。 –
mb_str_replace是你在找什麼 – ajreal