I wish to try taking some html content and work on a couple of particular characteristics inside a couple of particular tags.

I'm attempting to implement the next formula in PHP:

  • Find all 'a' tags as well as for each
    • if it is href attribute matches confirmed url
      • if the tag consists of an 'img' tag having a matching 'src' attribute
        • do stuff : may need altering contents/characteristics of current 'a' and 'img' tags
      • endif
    • endif
  • Next

I'm attempting to implement this inside a wordpress wordpress plugin therefore we can think that I've all of the functionality of this platform available.

What techniques/techniques can one use to implement this? i'm really bad with regular expressions and so i was wishing there can be an simpler method of doing this or maybe anybody can suggest a great way to build the standard expressions, that might be acceptable too.

any help could be greatly appreciated!

Anything you do create parse the HTML using regex!

Parse it having a parser :)

For instance DOM.

This seems like a great project for an HTML parser :)