3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Function to create a dynamic replacement. * @param array $match An array with the match of the pattern. * @return string The replacement. */ function getReplacement($match) { if (isset($match[0])) { return $match[0].'<br/>'; } } //the value to replace specific parts. $string = 'Tip #1 some #12 random #123 text #1234, an #12345 example #123456'; //replace all parts starting with '#' and three numbers following. echo preg_replace_callback('/#[0-9]+/', 'getReplacement', $string);

preferences:
51.74 ms | 402 KiB | 5 Q