6

How would you parse HTML in PHP?

 2 years ago
source link: https://www.programmerinterview.com/php-questions/how-would-you-parse-html-in-php/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

Has the problem already been solved?

It’s always good to remember that whenever you are looking to solve a difficult problem, look to see if someone else has already solved it – because in the real world, you will want to save as much time on the projects that you work on as possible. And, a lot of times if someone has encountered the same problem as you, then there may be a solution that is already out there on the Web.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK