Thursday, 15 August 2013

Regex in PHP: how to match any A and IMG HTML tag including content

Regex in PHP: how to match any A and IMG HTML tag including content

Suppose I have a text with a bunch (1 or more) of IMG and A and maybe
other HTML tags like this:
hello world hello world <a href='ads'>hello</a> bla bla foo bar <img
src='' />
I wanna to match in a regular expression for PHP any A and IMG tag. The A
tags should include the TAG content in the match. The other tags other
that A and IMG could be discarded for now.
So the result should be:
//match 1
<a href='ads'>hello</a>
//match 2
<img src='' />
Is there maybe a ready solution. Should I use REGEX ?

No comments:

Post a Comment