There are a ton of questions on SO about converting preg_replace
functions to preg_replace_callback
, but none of them seem to address my specific issue.
After much searching, I have tried this but don't think it is complete:
OLD CODE:
$terms = preg_replace(
"/\"(.*?)\"/e",
"search_transform_term('\$1')",
$terms
);
NEW CODE:
$terms = preg_replace_callback(
"/\"(.*?)\"/",
function ($m) {
return "search_transform_term('\$1')";
},
$terms
);
This code is supposed to split multiple search terms whether separated by spaces or commas.
I am updating someone's old code and there are several more associated functions that will also need to be converted, so I am trying to learn how to do it.
The question is: "How do I properly convert this preg_replace to preg_replace_callback?"
I am providing my new code to show that I have been working on it before asking, and if I can wrap my brain around it I intend to do the rest myself.
Please be kind, this is all quite new to me.