PHP, regex and lazy star

Hello

I need to write a line of code in PHP to remove image tags from a string.

I am trying the following...

echo eregi_replace("<img .*?>", "", "some string <img src=> with images <img src=   >");

...but keep getting the "Warning: eregi_replace(): REG_BADRPT in .../test.php on line ..." errormessage.

If I remove "?" from the regex it doesn't throw an error, but doesn't work as needed either doing a greedy match.

Please help

Thank you
AdmiralHorrorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomeeboyCommented:
Try this for removing image tags:

$string = preg_replace('/<img (.*?)src=(.*?)>/i', "", $string);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdmiralHorrorAuthor Commented:
Ok, that worked, thank you very much.

However, could you please explain to me the meaning of "/" in front of the "<" and the meaning of "/i"
TomeeboyCommented:
I think that the front slashes just define where the actual pattern starts/stops... though I'm not 100% sure on that :)  I always put them around a regex pattern for any PHP functions that use a regex pattern.  The "i" makes the pattern case insensitive.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.