<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>
我在数据库中有很多原始 html 字符串。所有的文字都有这些奇怪的字符。我怎样才能将其转换为普通文本以将其保存回数据库中。
$final = '<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>';
$final = utf8_encode($final);
$final = htmlspecialchars_decode($final);
$final = html_entity_decode($final, ENT_QUOTES, "UTF-8");
$final = utf8_decode($final);
echo $final;
我试过上面的代码,它在网络浏览器中正确显示,但仍然在数据库中保存相同的奇怪字符。
数据库的字符集是utf-8
$final = '<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>';
$final = str_replace("Â", "", $final);
$final = str_replace("’", "'", $final);
$final = str_replace("“", '"', $final);
$final = str_replace('–', '-', $final);
$final = str_replace('â€', '"', $final);
对于过去的数据,我用 UTF-8 字符替换了奇怪的字符。
为了将来的数据,我在 php、html 和数据库连接中将字符集设置为 utf8。
我是一名优秀的程序员,十分优秀!