0

我写了一个插件来删除博客非注册成员的链接,但是插件导致图片链接出错,下面是我写的内容过滤器:

if ( is_user_logged_in() ) {
    // Do nothing.  All is well.
} else {
    $doc = new DOMDocument();
    $doc->loadHTML($content);
    $dom_xpath = new DOMXpath($doc);

    foreach($doc->getElementsByTagName('a') as $link)
        $link->setAttribute('href', $UNREGISTERED_LINK_HREF);

    $texts = $dom_xpath->query('//a/child::text()');
    foreach ($texts as $text)
    {
        $text->data = $UNREGISTERED_LINK_TEXT;
    }

    $content = $doc->saveHTML();

}

正确的图片链接: http ://electrouniverse.net/wp-content/uploads/2012/08/Kyle-Geiger-%E2%80%93-Relentless-SOMA343D-240x240.jpg

过滤链接后: http ://electrouniverse.net/wp-content/uploads/2012/08/Kyle-Geiger-%C3%A2%C2%80%C2%93-Relentless-SOMA343D-240x240.jpg

我尝试使用 utf8_decode() 和 utf8_encode() 来解决这个问题,但它没有帮助。

4

1 回答 1

0

在之前使用以下内容$doc->loadHTML($content);

$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
于 2012-08-12T20:00:20.253 回答