我從utf8編碼的數據庫中獲取數據。但不知怎的,一些舊數據包含latin1字符。檢測utf8字符串中的latin1字符
所以這
$encod = mb_detect_encoding($string, 'UTF-8', true);
永遠是正確的。
總是使用utf8_decode()來檢查latin1字符(如'äöß')是否安全?
$string = utf8_decode($string);
$search = Array(" ", "ä", "ö", "ü", "ß", "."); //,"/Ä/","/Ö/","/Ü/");
$replace = Array("-", "ae", "oe", "ue", "ss", "-"); //,"Ae","Oe","Ue");
$string = str_replace($search, $replace, strtolower($string));
問候
怎麼樣'mb_detect_encoding($字符串,「ISO-8859-1,UTF -8',true);'? – ajreal
@ajreal我從數據庫中得到的字符串是'äääää'''code' mb_detect_encoding($ this - > _ name,'ISO-8859-1,UTF-8',true);'代碼'說'ISO-8859-1'和utf8_decode($ string)給出'ääää',我該怎麼辦? – spankmaster79
嘗試搜索iconv,MB轉換通過PHP手冊/ SO,應該有幾個問題在這裏討論之前 – ajreal