note 80877 deleted from function.preg-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 22:58:53 +0000 |
| Subject: | note 80877 deleted from function.preg-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137394@lists.php.net to get a copy of this message | ||
Note Submitter: swedish boy
----
This is another version of Hyperlink/URL replacement which handles most type of links. This one
worked better for me:
<?php
function hyperlink($text) {
// match protocol://address/path/file.extension?some=variable&another=asf%
$text = preg_replace("/([a-zA-Z]+:\/\/[a-z0-9\_\.\-]+".
"[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/",
" <a href=\"$1\" target=\"_blank\">$1</a>", $text);
// match www.something.domain/path/file.extension?some=variable&another=asf%
$text = preg_replace("/[^a-z]+[^:\/\/](www\.".
"[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/",
" <a href=\"http://$1\"
target=\"_blank\">$1</a>", $text);
// match name@address + ?subject etc...
$text = preg_replace(
"/([\s|\,\>])([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-z" .
"A-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})" .
"([A-Za-z0-9\!\?\@\#\$\%\^\&\*\(\)\_\-\=\+]*)" .
"([\s|\.|\,\<])/i",
"$1<a href=\"mailto:$2$3\">$2</a>$4",
$text);
?>