3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 0 => 'john', 1 => 'robinson', 2 => '27-08-1980', 3 => 'football', 4 => 'pizza', ]; $template = "{0} {1} birthday {2} <br /> Hobbie : {3} <br /> favorite : {4}"; $string = preg_replace_callback( '/\{(\d+)\}/', function ($matches) use ($data) { return $data[$matches[1]]; }, $template ); echo $string;

preferences:
28.44 ms | 404 KiB | 5 Q