1

I have a HTML file that I'm trying to parse. It has a bunch of DIVs like this:

<div class="doc-overview">
<h2>Description</h2>
<div id="doc-description-container" class="" style="max-height: 605px;">
<div class="doc-description toggle-overflow-contents" data-collapsed-height="200">
<div id="doc-original-text">
Content of the div without paragraph tags.
<p>Content from the first paragraph </p>
<p>Content from the second paragraph</p>
<p>Content from the third paragraph</p>

</div>
</div>
<div class="doc-description-overflow"></div>
</div>

I tried this:

foreach($html->find('div[id=doc-original-text]') as $div) {         
                echo $div->innertext;
            }

You notice that I directly find the doc-original-text but I also tried to parse from outer divs to inner divs.

7
  • 1
    Can you add the info like how do you want the output to be displayed? Just a sample? Commented Jul 25, 2012 at 10:44
  • i didn't understand, what are you wanting to get ? and what are you getting for the moment ? Commented Jul 25, 2012 at 10:47
  • just want to get all content within doc-original-text div... Commented Jul 25, 2012 at 10:47
  • The id attibute should be unique in the HTML document. Therefore the for loop does not make any sense. Commented Jul 25, 2012 at 10:48
  • 1
    @EdHeal : I can have more div with same class attribute , so for loop is needed in that case to iterate thru those elements. Commented Jul 25, 2012 at 10:56

1 Answer 1

1

Try This,

foreach($html->find('div#doc-original-text') as $div) {         
            echo $div->innertext;
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.