Jump to content

Coding help with mb_eregi_replace needed


upekshapriya

Recommended Posts

Hi

I'm pretty new to coding in php and am trying to simplify and standardise some html using mb_eregi_replace.

I want to remove the crud from image links in some text (actually from an RSS feed) as well as normal links. Then I want to make the image links use lightbox (javascript function) but not the normal links. The code I've found and modified so far is:

$itemtext = mb_eregi_replace("<a [^\>]*href=[\"']([^\"'\>]+)[\"'][^\>]*>[ ]*<img [^\>]*src=[\"']([^\"'\>]+)[\"'][^\>]*/>",
"<a href='\\1' rel='lightbox'><img src='\\2' alt='image'/>", $itemtext);

$itemtext = mb_eregi_replace("<a [^\>]*href=[\"']([^\"'\>]+)[\"'][^\>]*>",
"<a href='\\1' >", $itemtext);

The problem I'm finding is that in a chunk of text with both image links and normal links all of the links are being given rel='lightbox' which of course means the link doesn't work.

Is there any way to program this so that I can have image links and normal links modified as I want?

Kind regards

Upekshapriya
Link to comment
https://forums.phpfreaks.com/topic/27287-coding-help-with-mb_eregi_replace-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.