function text2links($str=”) {
if(!preg_match(‘/(http|www\.|@)/i’, $str)) { return $str; }
$lines = explode(“<br />”, $str); $new_text = ”;
while (list($k,$l) = each($lines)) {
// replace links:
$l = preg_replace(“/([ \t]|^)www\./i”, “\\1http://www.”, $l);
$l = preg_replace(“/([ \t]|^)ftp\./i”, “\\1ftp://ftp.”, $l);
$l = preg_replace(“/(http:\/\/[^ )!]+)/i”, “<a href=\”\\1\”>\\1</a>”, $l);
$l = preg_replace(“/(https:\/\/[^ )!]+)/i”, “<a href=\”\\1\”>\\1</a>”, $l);
$l = preg_replace(“/(ftp:\/\/[^ )!]+)/i”, “<a href=\”\\1\”>\\1</a>”, $l);
$l = preg_replace(“/([-a-z0-9_]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)+))/i”, “<a href=\”mailto:\\1\”>\\1</a>”, $l);
$new_text .= $l.'<br />’;
}
return $new_text;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。