Hi,
I'm not a regex man, so I need some help to make a search & replace!
I get from a table an article body and I want to find any anchor that as an image tag and apply a specific css class to the anchor;
Reading some tutorials I already reach something that I think it works, but I need to replace the string.
PHP Code:
$a = '<a href="image/test.gif"><img src="image/test.gif" /></a>';
if (preg_match("/^(<a href.*?<img src.*?<\/a>)$/", $a, $matches)) {
echo "Match was found <br />";
echo htmlspecialchars($matches[0])."<br>";
}
I need to find
'<a href' AND '
<img src' AND '
</a>' ... if it finds this pattern then should replace '
<a href' with '
<a href class="abcd"'.
Thanks
N
Edited: I forgot to mention that the image
must be the same in the anchor and in the image tag!