fork(5) download
  1. <?php
  2.  
  3. $array = ['name' => 'John', 'email' => 'john@gmail.com'];
  4. $string = 'Hi [[name]], your email is [[email]]';
  5. echo preg_replace_callback('/\[\[(.*?)]]/', function ($m) use ($array) {
  6. return isset($array[$m[1]]) ? $array[$m[1]] : $m[0];
  7. }, $string);
  8.  
Success #stdin #stdout 0.02s 23888KB
stdin
Standard input is empty
stdout
Hi John, your email is john@gmail.com