note 80877 added to function.preg-replace
| From: | swedishboy at osu1 dot php dot net | Date: | Tue, 05 Feb 2008 12:32:36 +0000 |
| Subject: | note 80877 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135788@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 129.16.214.50
Probable Submitter: 81.233.184.99
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/80877
Del: integrated -- https://master.php.net/note/delete/80877/integrated
Del: useless -- https://master.php.net/note/delete/80877/useless
Del: bad code -- https://master.php.net/note/delete/80877/bad+code
Del: spam -- https://master.php.net/note/delete/80877/spam
Del: non-english -- https://master.php.net/note/delete/80877/non-english
Del: in docs -- https://master.php.net/note/delete/80877/in+docs
Del: other reasons-- https://master.php.net/note/delete/80877
Reject -- https://master.php.net/note/reject/80877
Search -- https://master.php.net/manage/user-notes.php