我想处理一个日文页面,但会给出这个字符错误。
<?php
$profile="<div><p>イリノイ州シカゴにて、アイルランド系の家庭に、9</p></div>";
$dom = new DomDocument();
$dom->loadHTML(mb_convert_encoding($profile, 'HTML-ENTITIES', 'UTF-8'));
$divs = $dom->getElementsByTagName('div');
foreach ($divs as $div) {
echo $dom->saveHTML($div);
}
//or
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $profile);
?>
返回此值:
イリãƒã‚¤å·ã‚·ã‚«ã‚´ã«ã¦ã€ã‚¢ã‚¤ãƒ«ãƒ©ãƒ³ãƒ‰ç³»ã®å®¶åºã«ã€9
如何解决这个问题?
更新
我使用简单的 dom 解析器:
<?php
require_once("/simple_html_dom.php");
$html = str_get_html("<p>イリノイ州シカゴにて、アイルランド系の家庭に、9</p>");
echo $html->find('p', 0)->plaintext;
?>
返回 ã,¤ãƒªãƒã,¤å·ã,·ã, «ã,´ã«ã¦ã€ã,¢ã,¤ãƒ«ãƒ©ãƒ³ãƒ‰ç³»ã®å®¶åºã«ã€9