DOM UTF8日本字符集

时间:2013-09-09 07:51:44

标签: php character-encoding char

我想处理日文页面,但会出现此字符错误。

  <?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

2 个答案:

答案 0 :(得分:0)

我认为你的php文件文本编码是EUC。 我只能通过EUC或UTF-8执行此程序。 并且,UTF-8没有字符编码错误。 如果您安装了nkf,请尝试运行。

  1. 检查字符编码

      

    nkf --guess yourfile.php

  2. 更改字符编码

      

    nkf -s ./yourfile.php> ./sjis.php
      nkf -e ./yourfile.php> ./euc.php
      nkf -w ./yourfile.php> ./utf8.php
      nkf -j ./yourfile.php> ./jis.php

  3. 那些试着跑步的人 3-1。 sjis.php

      

    PHP注意:iconv():在第806行的/var/www/simple_html_dom.php中检测到输入字符串中的非法字符

    3-2。 euc.php

      

    ΥˤơɷϤβˡ9

    3-3。 utf8.php

      

    イリノイ州シカゴにて,アイルランド系の家庭に,9

    3-4。 php jis.php

      

    PHP警告:输入中出现意外字符:第3行/var/www/jis.php中的''(ASCII = 27)状态= 0   PHP解析错误:语法错误,意外'('在第3行的/var/www/jis.php中

答案 1 :(得分:0)

只是浏览器编码设置&#34; iso-8859-1&#34;现在

相关问题