fork(1) download
  1. <?php
  2. $replacements = array();
  3. $replacements["var1"] = "New variable here";
  4. $regex = '~\{\[([^]]+)\]}~';
  5.  
  6. $string = "This is some string with {[var1]} in it";
  7.  
  8. $regex,
  9. function ($match) use ($replacements) {
  10. return $replacements[$match[1]];
  11. },
  12. $string);
  13. echo $string;
  14.  
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
This is some string with New variable here in it