kwpreds Posted March 2, 2021 Share Posted March 2, 2021 (edited) I have the following line of code in my program $html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’,create_function(‘$matches’, ‘return date($matches[1]);’),$html ); I am getting a warning about it being deprecated. I have tried the following two lines separately and get an error with both. $html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’, function($matches) { return date($matches[1]); },$html ); $html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’, function($matches) { return date($matches[1]); },$html ); Can anyone help me convert from preg_replace to preg_replace_callback. Edited March 2, 2021 by kwpreds Quote Link to comment https://forums.phpfreaks.com/topic/312236-preg_replace-to-pred_replace_callback/ Share on other sites More sharing options...
maxxd Posted March 2, 2021 Share Posted March 2, 2021 What error have you gotten from both lines? Quote Link to comment https://forums.phpfreaks.com/topic/312236-preg_replace-to-pred_replace_callback/#findComment-1584849 Share on other sites More sharing options...
kwpreds Posted March 3, 2021 Author Share Posted March 3, 2021 (edited) I will go on the server error log and copy and paste the error. Edited March 3, 2021 by kwpreds Quote Link to comment https://forums.phpfreaks.com/topic/312236-preg_replace-to-pred_replace_callback/#findComment-1584856 Share on other sites More sharing options...
kwpreds Posted March 3, 2021 Author Share Posted March 3, 2021 (edited) If both lines look correct, I can try again. Thoughts? I made an error on one of the two lines used. These are the two lines. $html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’,create_function(‘$matches’, ‘return date($matches[1]);’),$html ); $html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’, function($matches) { return date($matches[1]); },$html ); Edited March 3, 2021 by kwpreds Quote Link to comment https://forums.phpfreaks.com/topic/312236-preg_replace-to-pred_replace_callback/#findComment-1584857 Share on other sites More sharing options...
maxxd Posted March 3, 2021 Share Posted March 3, 2021 create_callback is the function that's been deprecated - neither preg_replace nor preg_replace_callback have. The second bit of code looks OK from a cursory glance. What's the actual error message you're seeing from it? Quote Link to comment https://forums.phpfreaks.com/topic/312236-preg_replace-to-pred_replace_callback/#findComment-1584858 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.