Re: Regex question

From: Date: Fri, 13 Dec 2002 07:25:45 +0000
Subject: Re: Regex question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128128@lists.php.net to get a copy of this message
On Thu, Dec 12, 2002 at 11:01:47PM -0800, 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. How about: $href="(https?://([a-z0-9]+\.)+[a-z][a-z]+/[a-z0-9_./~%-]*)"; $repl="<a href='\\1'>\\1</a>"; $line=eregi_replace($href, $repl, $line); You can of course make $href less restrictive if you're liberal minded about your URL formats. -- Paul Chvostek <paul@it.ca> Operations / Abuse / Whatever +1 416 598-0000 it.canada - hosting and development http://www.it.ca/

« previous php.general (#128128) next »