Reputation:
I'm kinda stuck here, I made some preg coding to find any 11 digits numbers, but what I don't know how to make it use the found/matched to a function like "preg - time()"
Reminder, the 11 digits will might be found more than one time, so the function should be enable to be used on any of them, maybe a loop on a array or anything?
"#\d{11}#" - Quick example on the preg i might will use.
Help!
Upvotes: 1
Views: 76
Reputation: 18785
Use preg_replace_callback
to use a custom function to make changes to each of the matches.
function your_custom_function($matches){
$match = $matches[0];
// Do something with $match
return $match;
}
$string = preg_replace_callback(
"#\d{11}#",
"your_custom_function",
$string
);
Upvotes: 1
Reputation: 39532
preg_replace automatically replaces all, and preg_match_all will give you all the matches in the third parameter.
preg_match("/\d{11}/", "Quick example on the preg I might will use", $matches);
print_r($matches);
Upvotes: 0