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++; return $return; }, $body);

preferences:
33.39 ms | 404 KiB | 5 Q