php - preg_replace_callback with array
Get the solution ↓↓↓Solution:
The argument of the callback function is the array of matching groups.
I don't understand why you are using an array for the search and the replacement parts, I'd do:
$var = "[email protected]";
$var = preg_replace_callback(
'/(.)@(.)/',
function($match) {
return sprintf("&#%03d;@&#%03d;", ord($match[1]), ord($match[2]));
},
$var
);
echo $var,"\n";
Output:
abc@def.org
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.