Page 1 of 1

eregi_replace -> Preg_replace

Posted: Sun Jun 13, 2010 1:21 am
by AGISB
I got some problems changing the decaprecated eregi_replace to preg_replace as I have no real idea how to use the return and newline with preg_replace. My Problem mainly is, that this is part of a function that I haven't written myself, and I might have an idea what this part does, but not 100% sure. The first line appears to place an http:// when it was missing. I however have no clue why the return and newline is necessary, so I might need some help with this one to take over to preg_replace.

Code: Select all

 
$newtext = eregi_replace("([ \r\n])www\\.([^ ,\r\n]*)","\\1http://www.\\2",$newtext);
$newtext = eregi_replace("([ \r\n])http\:\/\/www\\.([^ ,\r\n]*)","\\1http://www.\\2",$newtext);

Re: eregi_replace -> Preg_replace

Posted: Sun Jun 13, 2010 6:44 pm
by Jonah Bron

Code: Select all

 
$newtext = preg_replace("/([ \r\n])www\\.([^ ,\r\n]*)/g", "\\1http://www.\\2", $newtext);
$newtext = eregi_replace("/([ \r\n])http\:\/\/www\\.([^ ,\r\n]*)/g", "\\1http://www.\\2", $newtext);
Not tested, but I think this will work.