note 42376 deleted from function.preg-replace by nlopess

From: Date: Mon, 17 May 2004 13:11:47 +0000
Subject: note 42376 deleted from function.preg-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-69713@lists.php.net to get a copy of this message
Note Submitter: interiority-doot-com ---- I've been searching for a URL replacer that could be embedded within a function that did some multiple preg_replace's, i.e. a small script that didn't rely on a single function alone but still checked to see if a URL was beginning with 'http://' or 'ftp://' etc. - or not. I've combined a few of the things here into something hopefully useable. It only writes the domain between the href: if ( preg_match("(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?i", $theText) ) { $theText = preg_replace( "(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?i", "<a href=\"$0\" target=\"_blank\">$4</a>", $theText); } else if ( preg_match("((\w|\.|\-|_)+)(/)?(\S+)?i", $theText) ) { $theText = preg_replace( "((\w|\.|\-|_)+)(/)?(\S+)?i", "<a href=\"http://$0\" target=\"_blank\">$1</a>", $theText); }#endif

« previous php.notes (#69713) next »