fork(3) download
  1. <?php
  2.  
  3. $re = '/\(link\)(.*?)\(\/link\)/';
  4. $str = "(link)there is &link1(/link), (link)there is link2(/link)";
  5. $result = preg_replace_callback($re, function ($m) {
  6. return "<a href=" . urlencode($m[1]) . "'>" . $m[1] . "</a>";
  7. }, $str);
  8. echo $result;
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<a href=there+is+%26link1'>there is &link1</a>, <a href=there+is+link2'>there is link2</a>