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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.