note 64020 added to function.preg-replace
| From: | cipriandotamarieiMtaiilgmail*com at osu1 dot php dot net | Date: | Wed, 05 Apr 2006 17:21:00 +0000 |
| Subject: | note 64020 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107393@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 212.93.155.36
Probable Submitter: 81.180.201.38 (proxied: 10.10.41.76)
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/note/edit/64020
Del: integrated -- http://master.php.net/note/delete/64020/integrated
Del: useless -- http://master.php.net/note/delete/64020/useless
Del: bad code -- http://master.php.net/note/delete/64020/bad+code
Del: spam -- http://master.php.net/note/delete/64020/spam
Del: non-english -- http://master.php.net/note/delete/64020/non-english
Del: in docs -- http://master.php.net/note/delete/64020/in+docs
Del: other reasons-- http://master.php.net/note/delete/64020
Reject -- http://master.php.net/note/reject/64020
Search -- http://master.php.net/manage/user-notes.php