skip to Main Content

Php – Extract all <a> and <img> tags (exactly as represented in the input) from HTML 5 that contain a specific class

I need to improve some open source code. It contains a function to extract all <a> and <img> tags with a specific class from a string that represents HTML. This function uses regular expressions: preg_match_all('#<img(.*)class="(.*)foo(.*)"(.*)>#Umsi', $text, $matches_img, PREG_PATTERN_ORDER); preg_match_all('#<a(.*)class="(.*)foo(.*)">(.*)</a>#Umsi', $text,…

VIEW QUESTION
Back To Top
Search