eregi_replace -> Preg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

eregi_replace -> Preg_replace

Post 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);
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: eregi_replace -> Preg_replace

Post 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.
Post Reply