0

Possible Duplicate:
Grabbing the href attribute of an A element

I am trying to preg_match_all tags to do specific stuff to them, however, there is one type of that I want to ignore the preg_match_all. I thought about giving the img a class so and for the preg_match_all to ignore all imgs with the class "ignored".

In other words, do a preg_Match_all and if you find the word "ignored", skip it.

my code so far is:

preg_match_all( '/<img\s+.*?>/', $content, $matches );

but that detecs all img, I'm stuck on how to ignore ones with the word "ignored" in it.

Hopefully someone can give me a hand, thanks guys.

Community
  • 1
  • 1
user1945912
  • 597
  • 3
  • 9
  • 19
  • [Use a DOM Parser](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662). – Gordon Jan 03 '13 at 15:22
  • or try [`xpath_match_all`](https://gist.github.com/1358174) with `//img[not(contains(@class, "ignored"))]` – Gordon Jan 03 '13 at 15:25

1 Answers1

1
$str = '<img src="path_to_image0"><img src="path_to_image1" class="ignored">';

preg_match_all("/<img(.*|!ignored)>/",$str,$matches);

echo '<pre>';
print_r($matches[1]);
echo '</pre>';
Samuel Cook
  • 16,620
  • 7
  • 50
  • 62