Jump to content

Weird eregi_replace problem


pureDesi

Recommended Posts

I'm trying to replace all occurrences of {image:*} with <img src='*' /> using eregi_replace and I'm getting some awkward results.

The following code is what I used, the output is shown below.

 

code in question:

$string = "This is a test {image:5.bmp} why won't you work! {image:test.jpg} grr";
$pattern = "{image:(.+)}";
echo eregi_replace($pattern, "<img src='files/\\1' />", $string);

 

output:

This is a test <img src='files/5.bmp} why won't you work! {image:test.jpg' /> grr

 

However, when there's only one occurrence of {img src='*'} in the string, it works like a charm. Do you guys have any clue as to why this is happening?

Thanks

Link to comment
Share on other sites

The pattern is wrong.... Technically that matches correctly since . can be any character and theres a /> farther down the road....

 

I would tell you the correct pattern, but I fail miserably at regexp and would probably make things worse. ;p

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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