fork(6) download
  1. <?php
  2.  
  3. $s = "Hello Mr/Mrs {{Name}}. You have subscribed for {{Service}} at {{Date}} {{I_DONT_KNOW_IT}}.";
  4. $arr = array(
  5. 'Name' => "customerName", //or string
  6. 'Service' => "serviceName", //or string
  7. 'Date' => '2015-06-06'
  8. );
  9. echo $res = preg_replace_callback('/{{(.*?)}}/', function($m) use ($arr) {
  10. return isset($arr[$m[1]]) ? $arr[$m[1]] : $m[0];
  11. }, $s);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Hello Mr/Mrs customerName. You have subscribed for serviceName at 2015-06-06 {{I_DONT_KNOW_IT}}.