PHP简单dom解析器一次选择并删除多个标记

PHP简单dom解析器一次选择并删除多个标记,php,Php,我正在使用PHP简单dom解析器。 我可以通过执行以下操作删除具有特定id的标记 $html = str_get_html('<div><div class="two">two</div></div>'); $e = $html ->find('.two',0); $e->outertext = ''; echo $html ->outertext; 这对我来说很好 我在上述代码中发现的问题与变量名类似。您的内容在$h

我正在使用PHP简单dom解析器。 我可以通过执行以下操作删除具有特定id的标记

$html = str_get_html('<div><div class="two">two</div></div>');     
$e = $html ->find('.two',0);
$e->outertext = '';
echo $html ->outertext;

这对我来说很好

我在上述代码中发现的问题与变量名类似。您的内容在$html中,但您正在使用$str变量查找div

$html = str_get_html('<div><div class="two">two</div><div class="three">thomas</div><div    class="four">babu</div></div>');     
$e = $html->find('#two , #three',0);
$e->outertext = '';
echo $html->outertext;
$html=str_get_html('twothomasbabu');
$e=$html->find('#2,#3',0);
$e->outertext='';
echo$html->outertext;

请退房。

它对我来说很好用

我在上述代码中发现的问题与变量名类似。您的内容在$html中,但您正在使用$str变量查找div

$html = str_get_html('<div><div class="two">two</div><div class="three">thomas</div><div    class="four">babu</div></div>');     
$e = $html->find('#two , #three',0);
$e->outertext = '';
echo $html->outertext;
$html=str_get_html('twothomasbabu');
$e=$html->find('#2,#3',0);
$e->outertext='';
echo$html->outertext;

请退房。

很抱歉给您带来困惑。根据简单的html dom解析器文档

// Find all anchors and images with the "title" attribute
$ret = $html->find('a[title], img[title]');

<div class="mainnavs">
    <ul>
        <li>Tags</li>
        <li>Users</li>
    </ul>
</div>

<div class="askquestion">
    <ul>
        <li>
            Ask Questions
        </li>
    </ul>
</div> 

很抱歉给你带来了困惑。根据简单的html dom解析器文档

// Find all anchors and images with the "title" attribute
$ret = $html->find('a[title], img[title]');

<div class="mainnavs">
    <ul>
        <li>Tags</li>
        <li>Users</li>
    </ul>
</div>

<div class="askquestion">
    <ul>
        <li>
            Ask Questions
        </li>
    </ul>
</div> 

这不是问题所在。这只是一个打字错误。下面是我的php文件的外观。这对我不起作用。试一下,我有它,让我知道它是否适合你。嗨,小指,我测试了当我改变“$html->find('.two,.one',0);”到$html->find('#two,#one',0);它起作用了。那不起作用。你能给我提供你的工作代码吗。$html=newsimple_html_dom()$html->load('testing1testing4')$e=$html->find('two,'one',0)$e->outertext='';echo$html->outertext;这不能是您的工作代码。在html加载中有类,但在代码中使用id。我不认为你已经测试过了,这不是问题所在。这只是一个打字错误。下面是我的php文件的外观。这对我不起作用。试一下,我有它,让我知道它是否适合你。嗨,小指,我测试了当我改变“$html->find('.two,.one',0);”到$html->find('#two,#one',0);它起作用了。那不起作用。你能给我提供你的工作代码吗。$html=newsimple_html_dom()$html->load('testing1testing4')$e=$html->find('two,'one',0)$e->outertext='';echo$html->outertext;这不能是您的工作代码。在html加载中有类,但在代码中使用id。我想你还没有测试过这个。