Re: Regex question

From: Date: Fri, 13 Dec 2002 09:39:39 +0000
Subject: Re: Regex question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128135@lists.php.net to get a copy of this message
Troy May wrote:
How would take a regular non-formatted text link (http://www.link.com) and turn it into ready to post HTML? (<a href=http://www.link.com>http://www.link.com</a>) Darn, Outlook formats it, but you get the idea. It would just be typed out normally. Any ideas?
function MakeUrl ($text) {
    $text =  preg_replace("/(www\.[a-zA-Z0-9\.\/#~:?+=&%@!_\\-]+)/", "http://\\1"  ,$text);#make www. -> http://www.
    $text = preg_replace("/(http:\/\/)(?!www)([a-zA-Z0-9\.\/#~:?+=&%@!_\\-]+)/", "\\1\\2"  ,$text); #eg-- http://kernel.org
    $text = preg_replace("/(http:\/\/)(www\.)([a-zA-Z0-9\.\/#~:?+=&%@!\\-_]+)/", "\\1\\2\\3" ,$text); #eg -- http://www.google.com -> <a href"http://www.google.com">www.google.com</a>
    return $text;
} -- Sean

« previous php.general (#128135) next »