Jump to content

How to convert this eregi_replace to preg_replace?


sastro

Recommended Posts

I need to convert eregi_replace to preg_replace. here is the code :

$str = eregi_replace("((([ftp://])|(http(s?)://))((:alnum:|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*))"," ",$str);
$str = eregi_replace("(([^/])www\.|(^www\.))((:alnum:|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*)"," ",$str);

 

It is a script to remove url in string.

 

Thanks in advanced

Are you sure that pattern is 100% correct even as a POSIX pattern? The square brackets around the ftp part means it likely doesn't do what you want it to do. There is a page in the documentation on the difference between POSIX and PCRE. Basically you will need to add delimiters (though in your case the unnecessary capture group around the whole pattern will actually work as the delimiters rather than a capture group, meaning it will run as is). The only other thing to remember is to add the i modifier since you are using eregi_. Should take you two minutes to fix using the PCRE section of the manual, but if you get stuck let us know.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.