简体   繁体   English

简单的html dom排除带有类的段落

[英]simple html dom to exclude paragraph with class

I have this code and i want first paragraph as output I tried to filter with paragraph but I am getting second paragraph 我有这段代码,我想将第一段作为输出,我试图用该段进行过滤,但是我得到了第二段

I am only interested in first paragraph text. 我只对第一段文字感兴趣。

   <div class="bq_fq_lrg" style="margin:0px">
     <p>this text i want.</p>
     <p class="bq_fq_a">
       <a href="xz.html">this text i dont want.</a>
     </p>
   </div>

I tried this but it is giving second paragraph 我试过了,但它给出了第二段

  foreach($html->find('div.bq_fq_lrg p[0]') as $e)

The $html variable is an instance of SimpleHtmlDom $html变量是SimpleHtmlDom的实例

I am getting the content of the paragraph like this: 我得到的段落内容是这样的:

 $op1 = $e->innertext . '<br>';

You can use the ! 您可以使用! in attributes to get that particular value. 属性以获取该特定值。 Consider this example: 考虑以下示例:

include 'simple_html_dom.php';
$html_string = '<div class="bq_fq_lrg" style="margin:0px">
     <p>this text i want.</p>
     <p class="bq_fq_a">
       <a href="xz.html">this text i dont want.</a>
     </p>
   </div>';
$html = str_get_html($html_string);
foreach($html->find('div.bq_fq_lrg p[!class]') as $value) {
    echo $value->innertext; // this text i want.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM