3v4l.org

run code in 300+ PHP versions simultaneously
<?php $body = "This is a body of {{awesome}} text {{blabla}} from a book."; //$count = 0; $terms[] = '1'; $terms[] = '2'; echo preg_replace_callback('/\{{2}(.*?)\}{2}/',function($match) use (&$count,$terms) { $return = !empty($terms[$count]) ? $terms[$count] : 'Default value for unknown term'; // $count++; echo "#$count#"; return $return; }, $body, -1, $count);

preferences:
54.94 ms | 402 KiB | 5 Q