Welcome to WebmasterWorld Guest from 54.227.52.24

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg_replace Error

Unknown modifier

     

Knowles

2:37 pm on Oct 2, 2002 (gmt 0)

10+ Year Member



Ok I am doing some ubb code for a forum I am getting this error:
Warning: Unknown modifier '/' in file.php on line 142

Line 142 is:
$msg = preg_replace("/[url](http://)?(.*?)[/url]/si", "<a href='12' target='_blank'>2</a>", $msg);

Any ideas what this means?

Knowles

3:33 pm on Oct 2, 2002 (gmt 0)

10+ Year Member



Ok I fixed the warning error by changing the line to this:
$msg = preg_replace("#/[url](http://)?(.*?)[/url]/si#", "<a href='12' target='_blank'>2</a>", $msg);

But now its not replacing it like it should. Any ideas?

andreasfriedrich

3:38 pm on Oct 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are using the slash as the delimiter for your regex. The engine will look for the first slash to end the expression.

Either choose a delimter that is not contained within your expression or escape the slashes.

Andreas

Knowles

3:51 pm on Oct 2, 2002 (gmt 0)

10+ Year Member



Thanks andreasfriedrich I just figured that out now to tackle the next issue. Thanks again for the help.

andreasfriedrich

2:07 am on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps you would like to post an example of a string you want to perform the replacement on? That would be helpful to test your expression.

BTW I didnīt see that you already solved the first problem when I posted my reply and was just too lazy to edit it.

Andreas

 

Featured Threads

Hot Threads This Week

Hot Threads This Month