note 34876 added to function.preg-replace-callback

From: Date: Sat, 09 Aug 2003 20:58:58 +0000
Subject: note 34876 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-53758@lists.php.net to get a copy of this message
Occasionally you will want to replace all HTML links with a printable URL and the label - for example, perhaps a wikipedia. This worked fine for me: preg_replace('/\<A HREF="?([^">]+)"?\>(.*)<\/A\>/U','<I>$2</I> [$1]',$input); so <A HREF="http://www.example.com">Place</A> becomes <I>Place</I> [http://www.example.com] It will work without the quotes around the URL but not if the A tag has extra properties. It also keeps HTML formatting - so <A HREF="place"><B>Universe</B></A> becomes <I><B>Universe</B></I> [place] Be warned - doing <A><B></A></B> is a bad idea generally, and here the </B> tag will not be picked up. ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34876 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34876&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34876&report=yes

« previous php.notes (#53758) next »