View Full Version : Problem with stars in preg_replace conversion
bojangles
01-18-2016, 01:23 PM
Need help with this
eregi_replace("title=\"([^\\[]*)\">link</a>\\]\\]","]",$text);
I've been using stars to convert to preg_replace but there is already a star present and it's giving more errors. How do I fix it?
Beverleyh
01-18-2016, 01:38 PM
I'm guessing that you're referring to a conflicting delimiter? If you regex has an asterisk (star) in it already, you can just use another character;
preg_replace("#title=\"([^\\[]*)\">link</a>\\]\\]#i","]",$text);This one uses '#' as the delimiter.
Is that what you mean? Does that help?
bojangles
01-18-2016, 02:10 PM
Thanks. That helps a bunch. Your code looks a little different to mine with the i at the end of the line. May I ask what that is for? Will it make a difference if I don't use it?
Beverleyh
01-18-2016, 02:16 PM
You original code used eregi_replace, which is for case-insensitivity, so the "i" after the # delimiter in the updated preg_replace function does the same thing - it makes the regex case-insensitive.
If case-insensitivity was in effect in the earlier version of your script, it would be best to keep it that way in the update to avoid any complications/incompatibilities with whatever text is being replaced.
bojangles
01-18-2016, 02:28 PM
Okay, I will change my code to match your example.
Thanks again for your help. I will probably need more help soon so I will return.
Beverleyh
01-18-2016, 02:33 PM
No problem. Come back any time :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.