php - How to preg_match_all the images which has a http head width>100px and height>80px? -


i want match imgs that:

  1. have 1 of extensions: jpg|png|gif
  2. whose src not begin http://
  3. 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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -