Back to Top

To grab content from nested tags in PHP

To grab content from nested tags in PHP

Recently I am working with the scraping of data from external URL and for scraping we always need to use a preg_match function to get matched data.

I want to fetch all “div” tags and their respective content and nested div’s through PHP function and I have used preg_match, but it’s creating an issue.
For example, I have syntax for HTML tags something like below

In from above code, I want to get everything within the div class=’xyz’ but preg_match function going to stop executing after getting the first tag.

So, I have used DOMDocumen for fetching all nested divs value within div class=’xyz’ using the nodeValue element of DOMDocument but it is not returning HTML tags within the div tag.

Here, I am going to explain how I solve above issue when try to fetch multiple nested divs in PHP so let’s see the code.

That’s it. you just need to change URL or code require to display.

Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (1)

  1. Nice Tutorial…keep up the good work
    Thanks For Sharing….i m gonna try this

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

A Beginner’s Guide To Composer

Posted on 1 year ago

Bhumi

What Is Making People Insane for Cake PHP?

Posted on 4 years ago

Bhumi

How To Reset resourceID in MODx

Posted on 5 years ago

Bhumi

Angularjs 2 Tutorial for Beginners

Posted on 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 4 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi