我从数据库获取utf8编码的数据。但不知何故,一些旧数据包含latin1字符。
所以这个
$encod = mb_detect_encoding($string, 'UTF-8', true);
始终是正确的。
总是使用utf8_decode()来检查像'äöüß'这样的拉丁文字符是否安全?
$string = utf8_decode($string);
$search = Array(" ", "ä", "ö", "ü", "ß", "."); //,"/Ä/","/Ö/","/Ü/");
$replace = Array("-", "ae", "oe", "ue", "ss", "-"); //,"Ae","Oe","Ue");
$string = str_replace($search, $replace, strtolower($string));
此致
答案 0 :(得分:0)
似乎没有utf8_encoding
:
<?php
$string = "äöüß";
$search = Array(" ", "ä", "ö", "ü", "ß", "."); //,"/Ä/","/Ö/","/Ü/");
$replace = Array("-", "ae", "oe", "ue", "ss", "-"); //,"Ae","Oe","Ue");
$string = str_replace($search, $replace, strtolower($string));
echo $string;
?>
答案 1 :(得分:-2)
使用htmlspecialchars();工作更安全。 更多信息: