1
<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

user1089802
  • 111
  • 4
  • 3
    [use an HTML parser](http://stackoverflow.com/a/1732454/855532) - check out [DOMDocument::loadHTML](http://php.net/manual/en/domdocument.loadhtml.php) for that. – vstm Dec 09 '12 at 14:37

2 Answers2

1

You can use the html-parser library aswell.

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

Ravi Sharma
  • 1,162
  • 3
  • 11
  • 20
0
<?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.

harry
  • 1,410
  • 3
  • 12
  • 31
  • $xpath->query( "//*[contains(@class, 'comment')]/p" ); get

    text3

    ?? receives 3 tag $mas[0]=text1;$mas[1]=text2;$mas[2]=text3; proceeding
    P.S. tag

    not everywhere is

    – user1089802 Dec 09 '12 at 16:08