Regex conditionals? in Regex Help Posted October 29, 2015 I'm using preg_replace for adding a text below images (my regex is here) /<img.+?>/i It's fine when the img is alone, it gets converted from <img src="image.jpg" border="0" alt="" /> to: <img src="image.jpg" border="0" alt="" /> <br /> Text added here However sometimes the image is contained on a link <a href="http://www.google.com/"><img src="image.jpg" border="0" alt="" /></a> So the text in this case is placed inside the <a href, which is not what i want <a href="http://www.google.com/"><img src="image.jpg" border="0" alt="" /> <br /> Text added here</a> I need to achieve something like this with regexes, but i'm not sure how can i do this. if(<img src="image.jpg" border="0" alt="" />){echo '<br /> Text here';}else if(<a href="http://www.google.com/"><img src="image.jpg" border="0" alt="" /></a>) {echo '<br /> Text here';}Thanks for the help!
Regex conditionals?
in Regex Help
Posted
I'm using preg_replace for adding a text below images (my regex is here)
It's fine when the img is alone, it gets converted from
to:
However sometimes the image is contained on a link
So the text in this case is placed inside the <a href, which is not what i want
I need to achieve something like this with regexes, but i'm not sure how can i do this.
if(<img src="image.jpg" border="0" alt="" />)
{
echo '<br /> Text here';
}
else if(<a href="http://www.google.com/"><img src="image.jpg" border="0" alt="" /></a>)
{
echo '<br /> Text here';
}
Thanks for the help!