user1089802
user1089802

Reputation: 111

PHP HTML preg_match_all

<div class="comment">
  <div class="pros">text1</div>
   <noindex>
    <div class="contras">text2</div>
   </noindex>
   <p>text3</p>
   <a few tags...>
</div>

 <div class="comment">
      <div class="pros">text1</div>
       <noindex>
        <div class="contras">text2</div>
       </noindex>
       <p>text3</p>
       <a few tags...>
    </div>

how to get the contents of the blocks ?

text1 text2

text3

preg_match_all ('/<div class=\"comment\"><div class=\"pros\">(.*?)<\/div><noindex><div class=\"contras\">(.*?)<\/div><\/noindex><p>(.*?)<\/p><\/div>/Uisu',$content,$found4);

Parser does not offer

Upvotes: 1

Views: 144

Answers (2)

Ravi Sharma
Ravi Sharma

Reputation: 1182

You can use the html-parser library aswell.

http://htmlparser.sourceforge.net/samples.html

Upvotes: 1

harry
harry

Reputation: 1522

<?php
 $html = new DOMDocument();
 @$html->loadHTML($source)
 $xpath = new DOMXPath( $html );
 $proslist = $xpath->query( "//*[contains(@class, 'pros')]" );
 foreach ($proslist as $list)
 {
    echo $list->nodeValue."\n";
 }
?>

This will help you in extracting the text1 specified in the div with class pros.$source represents your html.As said in the previous comment you have to look in parsing html with php and I hope this Reference link for parsing html with php will help you.

Upvotes: 0

Related Questions