note 71761 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:07:30 +0000 |
| Subject: | note 71761 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127715@lists.php.net to get a copy of this message | ||
Note Submitter: alexander dot knies at hs-bhv dot de
----
just one more function to create html-link-tags of out a text-url.
<?php
function find_url($string){
//"www."
$pattern_preg1 = '#(^|\s)(www|WWW)\.([^\s<>\.]+)\.([^\s\n<>]+)#sm';
$replace_preg1 = '\\1<a href="http://\\2.\\3.\\4" target="_blank"
class="link">\\2.\\3.\\4</a>';
//"http://"
$pattern_preg2 =
'#(^|[^\"=\]]{1})(http|HTTP|ftp)(s|S)?://([^\s<>\.]+)\.([^\s<>]+)#sm';
$replace_preg2 = '\\1<a href="\\2\\3://\\4.\\5" target="_blank"
class="link">\\2\\3://\\4.\\5</a>';
$string = preg_replace($pattern_preg1, $replace_preg1, $string);
$string = preg_replace($pattern_preg2, $replace_preg2, $string);
return $string;
}
?>