Jump to content
Sign in to follow this  
Oberti

Regex conditionals?

Recommended Posts

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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.