3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.2.9
####This is a body of Default value for unknown term text Default value for unknown term from a book.