note 47593 deleted from function.preg-replace by tularis

From: Date: Sun, 18 Jun 2006 13:22:09 +0000
Subject: note 47593 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114303@lists.php.net to get a copy of this message
Note Submitter: manithu at fahr-zur-hoelle dot org ---- This function is better than paul's, it 'stops' linking after a white-space. It also converts uris without http://(optional). <? function convert_links($str, $www = false) { #this converts http://* the link ends at the next space or(if there is no space) at the end of the string. $str = preg_replace('#(http://)([^\s]*)#', '<a href="\\1\\2">\\1\\2</a>', $str); #optional, replaces www.* if($www) { $str = preg_replace('=(www.)([^\s]*)=', '<a href="http://\\1\\2">\\1\\2</a>', $str); } return $str; } ?>

« previous php.notes (#114303) next »