我从 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));
问候