如何修改此功能,以便可以將target="_blank"
屬性添加到外部鏈接? 接受默認域example.com
PHP鏈接正則表達式
function makeLinks($text){
if(eregi_replace('(((f|ht){1}tp://)[[email protected]:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $text) != $text){
$text = eregi_replace('(((f|ht){1}tp://)[[email protected]:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $text);
return $text;
}
$text = eregi_replace('(www\.[[email protected]:%_\+.~#?&//=]+)', '<a href="http://\\1">\\1</a>', $text); // ([[:space:]()[{}]) deleted from beginnig of regex
$text = eregi_replace('([_\.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
[`ereg_replace()`和`eregi_replace()`](http://php.net/ereg_replace)已棄用。你應該切換到PCRE。 – jwueller 2010-12-06 17:41:40