23 February, 2010

Replace Links With Html

You can replace links with html tag using PHP regular expression.
Here is an example of it.
  1. function replace_link_with_link($string)
  2. {
  3.     $pattern = "|http://(\w+)([A-Z0-9-_:./?]+)*|i";
  4.     $string = preg_replace($pattern,'<a href="\0">\0</a>',$string);
  5.     return $string;
  6. }
Enjoy. Help Helpless.

No comments:

Post a Comment