note 19519 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 21:59:42 +0000
Subject: note 19519 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55678@lists.php.net to get a copy of this message
Note Submitter: jeff.roy@cruisingworld.com ---- I expnaded on some of the examples here to make all URL's and emails on our site links. I have found this set of replacements covers virtually all web addresses and email addresses. I am sure it could be done in a more concise manner, but this works. I found the examples previously posted missed a lot of addresses encountered on our site. $thisArticleText = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $thisArticleText); //make sure there is an http:// on all URLs $thisArticleText = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "<A TARGET=\"_blank\" HREF=\"$1\">$1</A>", $thisArticleText); //make all URLs links $thisArticleText = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\. ([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i", "<A HREF=\"mailto:$1\">$1</A>", $thisArticleText); //make all emails hot links NOTE: I had to put an extra line feed in the email expression to get this forum to accept my post. You will have to take it out in order for it to work

« previous php.notes (#55678) next »