note 57740 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Thu, 13 Oct 2005 07:57:11 +0000 |
| Subject: | note 57740 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96938@lists.php.net to get a copy of this message | ||
Note Submitter: Nick Bullock - SafireX
----
An improved function I put together to process HTML strings from a database or output buffer.
<?
function linkScan($string1)
{
$pattern1 = "/(?<![\/\d\w])(http:\/\/)?([\w\d\-]+)((\.([\w\d\-])+){2,})
([\/\?\w\d\.\-_&=+%]*)?/i";
$replace1 = "<a href=\\"http://$2$3$6\\"
target=\\"popup\\">$0</a>";
$string2 = preg_replace($pattern1,$replace1,$string1);
$pattern2 = "/[\d\w\.\-_]+@[\d\w\-_\.]+?\.[\w]{2,3}(\.[\w]{2,3})?/i";
$replace2 = "<a href=\\"mailto:$0\\">$0</a>";
$string3 = preg_replace($pattern2,$replace2,$string2);
return $string3;
}
?>