fork download
  1. <?php
  2. $string = '@[Carlos]({user}:529) is going to rock @[NEW YORK]({city}:111)';
  3. $regex = '/@\[([\w\s]*)]\({(\w*)}:(\d*)\)/';
  4.  
  5. $newString = preg_replace($regex, '<a href="/$2.php?id=$3">@$1</a>', $string);
  6.  
  7. echo $newString;
  8.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<a href="/user.php?id=529">@Carlos</a> is going to rock <a href="/city.php?id=111">@NEW YORK</a>