How can I find linked images in PHP?

I want to take some html content and operate on a few particular attributes in a few particular tags.

I am trying to implement the following algorithm in PHP:

Read More
  • Find all ‘a’ tags and for each
    • if its href attribute matches a given url
      • if this tag contains an ‘img’ tag with a matching ‘src’ attribute
        • do stuff : may require changing contents/attributes of current ‘a’ and ‘img’ tags
      • endif
    • endif
  • Next

I am trying to implement this within a wordpress plugin so we can assume that I have all the functionality of that platform available.

What methods/techniques can i use to implement this? i am really bad with regular expressions so i was hoping there might be an easier way to do this or if anyone can recommend a good way to build the regular expressions, that would be acceptable too.

any help would be greatly appreciated!

Related posts

Leave a Reply

2 comments