note 57737 deleted from function.preg-replace by tularis

From: Date: Wed, 12 Oct 2005 20:53:05 +0000
Subject: note 57737 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96919@lists.php.net to get a copy of this message
Note Submitter: Nick Bullock - SafireX Reason: useless ---- Here's a quick preg_replace function. It will scan an html or plain text string stored in a variable and change all web urls to html hyperlinks. These will popup in a new window. The ' target="popup" ' can easily be removed to make links appear in the current window. Useful when building forums and pulling messages or posts from a database or text file. Can also be used with <? ob_start(); ?> and <? $html = ob_get_clean(); ?> to process output buffer. For example any text matching: www.safirex.co.uk or http://www.safirex.co.uk etc. will be replaced with: <a href="http://www.safirex.co.uk" target="popup">www.safirex.co.uk</a> ----------------------------------------------------------- <? function linkScan($string) { $pattern = "/(http:\/\/)?www([\w\d\.\-]+)(\/[\w\d\.\-_]*)?/i"; $replace = "<a href=\\"http://www$2$3\\" target\\"popup\\">$0</a>"; return( preg_replace($pattern,$replace,$string) ); } ?> -----------------------------------------------------------

« previous php.notes (#96919) next »