您好,欢迎访问一九零五行业门户网

php domdocument中文乱码怎么办

php domdocument中文乱码的解决办法:首先打开相应的文件;然后进行编码声明,语句为“$dom->loadhtml(mb_convert_encoding($profile, 'html-entities','utf-8'))”。
推荐:《php视频教程》
php domdocument loadhtml出现乱码的解决方法
domdocument::loadhtml默认编码是iso-8859-1,所以我们需要做编码声明:
$dom->loadhtml(mb_convert_encoding($profile, 'html-entities', 'utf-8'));
完整测试代码:
$profile = '<div><p>イリノイ州シカゴにて、アイルランド系の家庭に、9</p></div>';$dom = new domdocument();$dom->loadhtml(mb_convert_encoding($profile, 'html-entities', 'utf-8'));echo $dom->savehtml($dom->getelementsbytagname('div')->item(0));
另一种方法是在loadhtml的字符前加上编码声明:
$dom->loadhtml('<?xml encoding="utf-8" ?>' . $profile);
以上就是php domdocument中文乱码怎么办的详细内容。
其它类似信息

推荐信息