note 78359 added to function.preg-replace
| From: | Mac at osu1 dot php dot net | Date: | Mon, 08 Oct 2007 14:18:23 +0000 |
| Subject: | note 78359 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131228@lists.php.net to get a copy of this message | ||
Here's a derivate of Iasmin's function.
This one handles URL's followed by a period or comma too and adds a _blank target to the
hyperlinks.
Additionally it replaces e-mail addresses with a mailto hyperlink.
<?php
function hyperlink($text) {
// match protocol://address/path/file.extension?some=variable&another=asf%
$text = preg_replace("/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*
[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/i",
" <a href=\"$1\" target=\"_blank\">$1</a>$2", $text);
// match www.something.domain/path/file.extension?some=variable&another=asf%
$text = preg_replace("/\s(www\.[a-z][a-z0-9\_\.\-]*
[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/i",
" <a href=\"http://$1\"
target=\"_blank\">$1</a>$2", $text);
// match name@address
$text = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*
\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/i",
" <a href=\"mailto://$1\">$1</a>$2", $text);
return $text;
}
?>
----
Server IP: 85.12.26.134
Probable Submitter: 213.160.196.156
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/78359
Del: integrated -- https://master.php.net/note/delete/78359/integrated
Del: useless -- https://master.php.net/note/delete/78359/useless
Del: bad code -- https://master.php.net/note/delete/78359/bad+code
Del: spam -- https://master.php.net/note/delete/78359/spam
Del: non-english -- https://master.php.net/note/delete/78359/non-english
Del: in docs -- https://master.php.net/note/delete/78359/in+docs
Del: other reasons-- https://master.php.net/note/delete/78359
Reject -- https://master.php.net/note/reject/78359
Search -- https://master.php.net/manage/user-notes.php