Q:

Efficient way to parse html in PHP?

When I parse html I always go with the most intuitive way that is to preg_match the page source. I know there are parsers that get the job done with more economical code, such as PHP Simple HTML DOM Parser , but I'm not sure whether parsers are faster than preg_match when I need only a smattering of values from the source. 
So, is using parsers faster or just to make the code look better? Assuming we don't use inefficient regex for preg_match.

A:

It's generally not good idea to parse HTML/XML with regexp. There are lot of special situations which regexp cannot handle - the tag split into several lines, & entities, CDATA and many others.
The real parser (either DOM or SAX if the text is actually xml) is quite quick and the reliability is incomparable.

