fork download
  1. <?php
  2. $text = 'Hey @Mathw, have u talked with @Jhon today?';
  3. preg_match_all('/@[a-z0-9]+/sim', $text , $handles_array, PREG_PATTERN_ORDER);
  4. $text = preg_replace('/(@[a-z0-9]+)/sim', '<a href="profile.php?user=$1">$1</a>', $text);
  5. print($text);
  6. print_r($handles_array[0]);
Success #stdin #stdout 0.02s 23656KB
stdin
Standard input is empty
stdout
Hey <a href="profile.php?user=@Mathw">@Mathw</a>, have u talked with <a href="profile.php?user=@Jhon">@Jhon</a> today?Array
(
    [0] => @Mathw
)