note 78802 deleted from function.preg-replace by felipe

From: Date: Mon, 10 Dec 2007 02:18:37 +0000
Subject: note 78802 deleted from function.preg-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133102@lists.php.net to get a copy of this message
Note Submitter: info at oscaralexander dot com ---- @ Mac: Your adjustment only seems to work when the period or comma is followed by a newline. The code breaks when more characters follow. Try the following code instead. It parses the url to a point where all punctuation is followed by either a word character or a slash. <?php $string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2">\\2</a>', $string); $string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2">\\2</a>', $string); $string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string); ?> This seems fairly waterproof but please post your improvements.

« previous php.notes (#133102) next »