Jquery PHP DOM元素无法处理strong、anchor、div等HTML标记
我们的问题和你的完全一样 我已经在我的项目中使用了这段代码,它工作得很好,但问题是我想加载该div标记中可用的所有HTML标记,如strong、anchor、div等,但我不知道如何做到这一点 我们使用了以下代码:Jquery PHP DOM元素无法处理strong、anchor、div等HTML标记,jquery,html,custom-post-type,posts,Jquery,Html,Custom Post Type,Posts,我们的问题和你的完全一样 我已经在我的项目中使用了这段代码,它工作得很好,但问题是我想加载该div标记中可用的所有HTML标记,如strong、anchor、div等,但我不知道如何做到这一点 我们使用了以下代码: <?php while (have_posts()) : the_post(); ob_start(); // run the_content() through the Output Buffer the_content(); $html = ob_get_c
<?php while (have_posts()) : the_post();
ob_start(); // run the_content() through the Output Buffer
the_content();
$html = ob_get_clean(); // Store the formatted HTML
$content = new DomDocument(); // Create a new DOMDocument Object to work with our HTML
$content->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'. $html );
$finder = new DomXPath( $content ); // Create a new DOMXPath object with our $content object that we will evaluate
$classname = 'TEST'; // The class we are looking for
$item_list = $finder->query("//*[contains(@class, '$classname')]"); // Evaluates our content and will return an object containing the number of items matching our query
?>
<div id = "result">`
<?php
// echo the value of each item found
// You might want to format or wrap your $value according to your specification if necessary
for( $i = 0; $i < $item_list->length; $i++ ){
$value = $item_list->item( $i )->nodeValue;
echo $value; //die();
?>
<?php
// if you want the text to be a link to the post, you could use this instead
// echo '<a href="' . get_the_permalink() . '">' . $value . '</a>';
}
?>
其输出如下所示:
知识是一种美德,是一种美德,是一种美德,是一种美德。但是,在最低限度上,我们需要一个实验室来进行日常工作。两人或两人在一个无教区的房间里互相指责。除偶尔因疏忽而死亡外,不得因疏忽而导致动物死亡
但我们需要下面的类型响应
Lorem ipsum dolor sit amet
他是一位杰出的职业经理人,他在劳动和就业方面的贡献是暂时的。但是,在最低限度的情况下,ullamco Laboratoris nisi和aliquip ex eacommodo consequat的操作。两人或两人在一个无教区的房间里互相指责。除偶尔因疏忽而死亡外,不得因疏忽而导致动物死亡
有人能帮我吗