Jump to content

Really need help fixing deprecated preg_replace()


CrystalSeabolt
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi guys I have an older script that I just rolled back out and I'm getting the following error....

 

preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

 

Below is my line of code and I'm failing at fixing this.

 

$text = preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\')', $text);

 

Any help would be greatly appreciated!! :wub:

Link to comment
Share on other sites

Thanks Ch0cu3r! :-*

 

I actually had one more instance of this line but it was a little different and I figured I would be able to figure it out with the new code from the line above... I WAS WRONG :o

 

Would you be able to show me the fix for this last line?

$text = preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2://$3\')', $text);

Your fix worked great.. but I am unable to apply it to this line.

Link to comment
Share on other sites

  • Solution

All you need to is replace  preg_replace  to  preg_replace_callback   and remove the  e  pattern modifier from the regex. Next replace  '\'$1\'.handle_url_tag(\'$2://$3\')'   to the callback function I gave earlier, inside the callback function change  {$m[1]}.{$m[2]}  to  {$m[1]}://{$m[2]}  lastly only pass $url once, rather than twice when calling the handle_url_tag function

Edited by Ch0cu3r
  • Like 1
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.