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);
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
####This is a body of Default value for unknown term text Default value for unknown term from a book.

preferences:
200.23 ms | 405 KiB | 211 Q