【问题标题】:php getElementsByTagName with nodeValue returns evil characters带有 nodeValue 的 php getElementsByTagName 返回邪恶字符
【发布时间】:2012-04-06 19:18:25
【问题描述】:

我有一些像这样的 utf-8 html:

<a href="http://example.com">Today 11:12 AM</a>

getElementsByTagName('a')->item(0)->nodeValue 会返回这个:

Today 11:12 AM

我在这个 html 中的其他节点没有任何问题。

我做错了什么?

【问题讨论】:

    标签: php getelementsbytagname nodevalue


    【解决方案1】:

    尝试显式设置 DOMDocument 对象的编码:

    $dom = new DOMDocument('1.0', 'UTF-8');
    

    【讨论】:

      【解决方案2】:

      源文件是 ASP 和 IIS。

      我最终将它用于违规角色:

      str_replace( chr(), chr(), $html);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 1970-01-01
        • 2016-11-18
        • 2011-01-02
        • 2010-10-11
        • 2011-01-02
        • 1970-01-01
        相关资源
        最近更新 更多