23 February, 2010

Regular Expression To Replace All Mentioned Name With Link

In twitter Rana vai gave me a code to replace all mentioned name with link like twitter. Check that.
There was 2 problem.
  1. I anyone use '.' after mentioned name then there will be '.' in link.
  2. There will be '@' in link.
Here is a function. I hope it will work perfectly

  1. function link_from_at($string)
  2. {
  3.     $status = preg_replace("|@([a-zA-Z0-9]+)*|",'@<a href="\1">\1</a>',$string);
  4.     return $status;
  5. }

No comments:

Post a Comment