note 79204 deleted from function.preg-replace by felipe

From: Date: Sun, 23 Mar 2008 23:00:07 +0000
Subject: note 79204 deleted from function.preg-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137400@lists.php.net to get a copy of this message
Note Submitter: t3k ---- Mac's post from 08-Oct-2007 04:18 inadvertently left out the '=' part of the query string. I've added the '=' and copied his method (modified from Iasmin's) here: <?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; } ?> PS - please note that the line breaks and spaces/tabs in the method's regular expressions need to be removed before using it.

« previous php.notes (#137400) next »