note 64020 deleted from function.preg-replace by colder

From: Date: Mon, 18 Jun 2007 20:00:49 +0000
Subject: note 64020 deleted from function.preg-replace by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127693@lists.php.net to get a copy of this message
Note Submitter: ciprian dot amariei Mtaiil gmail * com ---- I found some situations that my function bellow doesn't perform as expected. Here is the new version. <?php function make_links_blank( $text ) { return preg_replace( array( '/(?(?=<a[^>]*>.+<\/a>) (?:<a[^>]*>.+<\/a>) | ([^="\'])((?:https?|ftp):\/\/[^<> \n\r]+) )/iex', '/<a([^>]*)target="?[^"\']+"?/i', '/<a([^>]+)>/i' ), array( "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))", '<a\\1', '<a\\1 target="_blank">' ), $text ); } ?> This function replaces links (http(s)://, ftp://) with respective html anchor tag, and also makes all anchors open in a new window.

« previous php.notes (#127693) next »