fork download
  1. <?php
  2.  
  3. $values = array('firstname'=>'Eric', 'lastname'=>'Johnsson');
  4. echo preg_replace_callback("/{([^{}]*)}/", function($m) use ($values) {
  5. return !empty($values[$m[1]]) ? $values[$m[1]] : $m[0];
  6. }, "{lastname}, {firstname} {somestring}");
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
Johnsson, Eric {somestring}