3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "I went to the dog park yesterday and saw @dog4 playing with @dog8 and @dog3 drinking water -- poor @dog33."; $lookup = [ 'dog4' => 4, 'dog8' => 8, 'dog3' => 3, ]; echo preg_replace_callback( '/@(\w+)/', function ($m) use($lookup) { return isset($lookup[$m[1]]) ? "<span onclick='openPage(\"dogs.php?id={$lookup[$m[1]]}\")' role='link' tabindex='0'>{$m[0]}</span>" : $m[0]; }, $text );

preferences:
27.01 ms | 404 KiB | 5 Q