note 29349 added to function.preg-replace

From: Date: Mon, 10 Feb 2003 23:45:03 +0000
Subject: note 29349 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-43749@lists.php.net to get a copy of this message
here's another way to link urls in text. unlike the others i see here, this one doesn't link urls that have already been linked so you won't get <a href="<a href="http://www.blah.com">http://www.blah.com</a>">link</a> if your text ($txt) already has links in it. it's been quickly tested with uppercase, lowercase, http and ftp, secure urls, ports and query strings. it won't work if the url has spaces in it, but if you convert them to %20 it'll be ok. $txt = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">\\0</a>", $txt ); -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+29349 http://master.php.net/manage/user-notes.php?action=delete+29349 http://master.php.net/manage/user-notes.php?action=reject+29349

« previous php.notes (#43749) next »