Showing posts with label PHP Parsing HTML. Show all posts
Showing posts with label PHP Parsing HTML. Show all posts

Thursday, 4 September 2014

How would you parse HTML in PHP?

If you have programmed in PHP, you may have come across the need to parse an HTML document at some point – because it is something that needs to be done in many different scenarios.

But, how should you approach this problem? The first answer that you may think of is to use regular expressions, since they are good for finding patterns in strings.

However, the reality is that HTML documents can be quite complex, and trying to find patterns through regular expressions can become quite difficult and painful.

But there is good news – there is already a library in PHP that is meant for parsing HTML: Parse HTML in PHP.