note 78359 deleted from function.preg-replace by felipe

From: Date: Sun, 23 Mar 2008 23:00:54 +0000
Subject: note 78359 deleted from function.preg-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137403@lists.php.net to get a copy of this message
Note Submitter: Mac ---- 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; } ?>

« previous php.notes (#137403) next »