Jump to content

preg_replace to pred_replace_callback


Recommended Posts

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 by kwpreds
Link to post
Share on other sites
Posted (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 by kwpreds
Link to post
Share on other sites

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?

Link to post
Share on other sites

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.