How to parse HTML using PHP?

Possible duplicate:
How to parse and process HTML using PHP?

Suggestion for reference . There are dozens of "How to parse HTML" questions that appear every day. However, it is very difficult to close as a duplicate, because most of the questions relate to the specific scenario presented by the appellant. This question is an attempt to build a general "reference question" that covers all aspects of the problem.

This is an experiment. If such a reference question already exists, let me know and I will gladly delete this one.

My ideal vision is that each of the three questions gets an answer separately, and the best answers for each bubble up.

I will award 200 bounties with the best answer in each of the three categories in two weeks, pending discussion of this issue on Meta strong>.

Each of these questions has already received a brilliant answer elsewhere, so copying + pasting my own answer to another question is fine with me.

How to parse HTML using PHP?

  • What libraries exist? Which ones use the PHP DOM, which have their own parsing engine? (Hint: SimpleHTMLDOM)

    1a. I need to find a specific item, but it's hard for me to get used to the XPath syntax. Are there any DOM-based libraries that simplify HTML parsing? Please consider creating common examples in the real world.

  • Is there a PHP library that allows me to query the DOM using CSS [2/3] selectors like jQuery? (Hint: phpQuery). Please consider creating common examples in the real world.

  • Bonus question: why shouldn't I use regular expressions? Please provide a very short answer in layman's terms.

+56
html php regex html-parsing
Sep 06 2018-10-10T00:
source share

No one has answered this question yet.

See similar questions:

2024
How do you parse and process HTML / XML in PHP?
42
Remove style attribute from HTML tags
13
Best way to parse invalid HTML in PHP
7
How can I extract all anchor tags, their hrefs and their anchor text inside a string?
7
best way to replace query string value in given url
5
preg_replace throws seg fault
four
scanning html page using php?
3
How can I find the contents of the first h3 tag?
3
PHP parses HTML strings based on class name
2
Find multiple patterns with a single preg_match_all in PHP

or similar:

7205
Why does HTML consider chucknorris to be a color?
4270
Link. What does this symbol mean in PHP?
4078
How to center <div> horizontally?
3999
How to replace all occurrences of a string?
3998
How to check email address in JavaScript
2776
How can I prevent SQL injection in PHP?
2024
How do you parse and process HTML / XML in PHP?
1475
Convert HTML + CSS to PDF using PHP?
1111
"Note: undefined variable", "Note: undefined index" and "Note: undefined offset" using PHP
1065
Link. What does this error mean in PHP?



All Articles