CrystalSeabolt Posted August 23, 2015 Share Posted August 23, 2015 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!! Quote Link to comment Share on other sites More sharing options...
scootstah Posted August 23, 2015 Share Posted August 23, 2015 Did you try checking the manual for that function? http://php.net/manual/en/function.preg-replace-callback.php Quote Link to comment Share on other sites More sharing options...
CrystalSeabolt Posted August 23, 2015 Author Share Posted August 23, 2015 Not very good with PHP just HTML... this is the only error this old script has and that manual is alien to me. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted August 23, 2015 Share Posted August 23, 2015 (edited) Try $text = preg_replace_callback('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#i' , function ($m) { $url = "{$m[1]}.{$m[2]}"; return $m[0] . handle_url_tag($url, $url); } , $text); Edited August 23, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
CrystalSeabolt Posted August 23, 2015 Author Share Posted August 23, 2015 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 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. Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted August 23, 2015 Solution Share Posted August 23, 2015 (edited) 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 August 23, 2015 by Ch0cu3r 1 Quote Link to comment Share on other sites More sharing options...
CrystalSeabolt Posted August 23, 2015 Author Share Posted August 23, 2015 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.