PHP Preg match all

rankdominator

Junior Member
Joined
Dec 18, 2009
Messages
120
Reaction score
68
Hi,

If anybody can assist that would be appreciated.

Ive got some text which Im trying to parse and strip out the images, but I do not want to strip out images that are only height=1 pixel or width =1 pixel

This is the code at the moment

PHP:
preg_match_all('/<img(.+?)src=\"(.+?)\"(.*?)>/', $text, $out);
and it strips out everything - i mean all images. I only want images greater than a certain size


Im not an expert on preg_match - thats for sure.
 
the code above is doing just as you described since youre not giving it any delimiter to indicate size. you need to indicate a match for width="1" height="1" as well. however, this is not a requirement in html4 or 5 to be valid. so if its not on the page.. youll need to figure out a way to get the image height without depending on the page itself.
 
the code above is doing just as you described since youre not giving it any delimiter to indicate size. you need to indicate a match for width="1" height="1" as well. however, this is not a requirement in html4 or 5 to be valid. so if its not on the page.. youll need to figure out a way to get the image height without depending on the page itself.

All the images have width and height attributes so that I suppose is good . How would I then go about adding a filter to the above preg match to only match where the height was for example greater than 10
Posted via Mobile Device
 
first of all add the height and weight attributes into the regular expression, using a \d+

PHP:
foreach($out[0] as $img){
if(preg_match(<='1', $img)) { unset($img); }
  };

P.S. - I haven't / couldn't have test this code, you haven't provided an applicable example/regex.
 
Hi all,

I came right by removing all the images with height =1 and width =1 first, then parsed the remaining text and got the remaining images ...

Thanks for all the suggestions
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock