<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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)