Parse html with preg_match and preg_match_all

For the most of the web developer which are using the function preg_match, is the function preg_match_all a smaller advantage, but for all others it’s maybe hard to understand. The biggest difference between preg_match_all and the regular preg_match is that all matched values are stored inside a multi-dimensional array to store an unlimited number of matches. The first part of this preg_match_all. tutorial is about how to “collect” the image source values inside a web page. For many other  parts in a HTML document is the preg_match function more useful, that’s why I added two other examples: A PHP backlink checker and a example that extracts the title and META description from a webpage.

$data = file_get_contents("");
$pattern = "/src=["']?([^"']?.*(png|jpg|gif))["']?/i";
preg_match_all($pattern, $data, $images);


Subscribe to our company!

Sign up to receive New Technology and Website!