I need a regex to extract all the stylesheets (<link> tags) from a html document.
Currently i have preg_match_all('/<link([^>]*?)>/i',..., and that regex extracts the stylesheets… that’s fine.
But, I need to exclude the styles wrapped in IEs conditional tags <!--[if IE...]>bla bla<![endif]-->…
Any tips on how to do that?
Use DOM and XPath for that
This will only print the stylesheets in the head element excluding those inside comment nodes. And if you need to limit that even further, for instance by media attribute then simply add that as another condition to the Xpath query.
In case saveHTML doesnt accept a node in your version of PHP see