fork(2) download
  1. <?php
  2.  
  3. $text = "Hello there {{{name}}}!\nDid you try to {{{hack}}} me?";
  4.  
  5. $pattern = '/{{{([a-zA-Z_]+)}}}/';
  6.  
  7. $text = preg_replace_callback($pattern, 'produce_replacement', $text);
  8. echo $text;
  9.  
  10. function produce_replacement($match) {
  11. $producerName = 'evaluate_'.strtolower($match[1]);
  12. return function_exists($producerName) ? $producerName() : null;
  13. }
  14.  
  15. function evaluate_name() {
  16. return "Joe";
  17. }
  18.  
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Hello there Joe!
Did you try to  me?