Using preg_replace_callback
, is it possible to replace only one backreference? Or do I have to return the entire thing?
I\'m just trying to wrap the tok
I recently came up with a way more simple way of doing this.
For example; if I want to match \w+\d+\w+
and only change the digits.
$value = preg_replace_callback('~(\w+)(\d+)(\w+)~', function($match) {
$match[2] = $match[2] * 2;//Do whatever I want to $match[2]
return $match[1] . $match[2] . $match[3];
}, $value);
Very clean!