Today I will write about one great php parser that made my coding easier last week. Last Wednesday I had to scrape some html code, extract all necessary data that was around 50 different values positioned all over html and store in php array for further use.
When I started creating my script I thought how it will be very easy if this was coded in JavaScript/jQuery instead PHP, we would have used JS predefined functions and get the data based on ids, class attributes and other info...
I did quick search on internet to check if there is some good php parser that would do exact what is possible to do with JS and I found
PHP Simple HTML DOM Parser.
What is PHP Simple HTML DOM Parser?
This is HTML DOM Parser written in PHP that gives you all needed functions to easily manipulate with any HTML.
- Supports invalid HTML.
- Find tags on an HTML page with selectors just like jQuery.
- Extract contents from HTML in a single line.
What can you do with PHP Simple HTML DOM Parser?
With HTML DOM Parser you can do everything that you can with JavaScript when working with HTML like:
- Extract HTML content directly from URL, string or HTML file, DOM element can be created on 2 ways, Normal and Object-oriented
- Get HTML elements by tag, attribute or by using descendant and nested selectors
- Modify HTML elements - Gee/Set/Remove attributes and Insert/Append/Remove elements
and more...
Few Examples
Let me show you with few examples what this powerful script can do...
Create DOM Element
Quick Way:
Hello!