<?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);
You have javascript disabled. You will not be able to edit any code.