fork download
  1. <?php
  2.  
  3. $re = '~{([PF])}(.*?){/\1}~';
  4. $str = "{P}Haribo{/P}";
  5. $slug = "link";
  6. $urihash = "66";
  7. $subst = '<a href="#projects/' . $slug . '/' . $urihash . '">$2</a>';
  8. echo $result = preg_replace($re, $subst, $str);
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
<a href="#projects/link/66">Haribo</a>