我写了一个插件来删除博客的非注册成员的链接,但插件导致图片链接出错,下面是我写的内容过滤器:
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();
}
我尝试使用utf8_decode()和utf8_encode()来解决这个问题,但它没有帮助。
答案 0 :(得分:0)
在$doc->loadHTML($content);
:
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');