Source Code:
(back to article)
<?php $patterns_and_callbacks = [ '/(\w+)/i' => function ($matches) { return strtoupper($matches[0]); }, '/(\d+)/' => function ($matches) { return $matches[0] + 1; }, ]; $string = 'This is a test string with 1234'; $new_string = preg_replace_callback_array($patterns_and_callbacks, $string); echo $new_string;
Result:
Report an issue