我有下面的代码,我试图从我的wordpress文章中提取文本,并且只能回显div中的文本内容。 (我从后去除引用文字,图片等,以在别处使用)WordPress的内容(文本)没有显示
<?php
$content = get_the_content();
$content = wpautop($content);
$doc = new DOMDocument();
$doc->loadHTML(get_the_content(), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DOMXPath($doc);
foreach ($xpath->query('//blockquote') as $node) {
$node->parentNode->removeChild($node);
}
foreach ($xpath->query('//img') as $node) {
$node->parentNode->removeChild($node);
}
foreach($xpath->query('//p[not(node())]') as $node) {
$node->parentNode->removeChild($node);
}
$content = $doc->saveHTML($doc);
?>
<div>
<?php echo $content ?>
</div>
但内容不会出现。
您必须使用strip_tag从内容中移除html标签。 http://www.w3schools.com/php/func_string_strip_tags.asp –