AdmiralHorror
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
However, could you please explain to me the meaning of "/" in front of the "<" and the meaning of "/i"