php - How to preg_match_all the images which has a http head width>100px and height>80px? -
i want match img
s that:
- have 1 of extensions: jpg|png|gif
- whose
src
not beginhttp://
- whose width > 100 , height > 100
i started regular expression:
preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.(jpg|png|gif))\\2/i",$str,$matches);
numeric comparisions in regular expressions not simple, , finding width= , height= attributes necessitate way more complex regular expression. see regex tools
hence 1 of cases simpler html parser make sense. example querypath use:
foreach (qp($html)->find("img, a") $img) { if ($img->attr("width") >= 100 , ...) { echo $img->attr("src"), $img->attr("href"); } }
of course using domdocument faster (and more typing..)
Comments
Post a Comment