<?php
//函數一
function makeClickableLinks($text)
{
$text = preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
'<a href="\\1">\\1</a>', $text);
$text = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i',
'<a href="mailto:\\1">\\1</a>', $text);
return $text;
}

//函數二
function AddLink2Text($str) {
$str = preg_replace("#(https://[0-9a-z._/,-?=&;\+]+)#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $str);
$str = preg_replace("#(http://[0-9a-z._/,-?=&;\+]+)#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $str);
$str = preg_replace("#([0-9a-z._]+@[0-9a-z._?=]+)#i","<a href=\"mailto:\\1\">\\1</a>", $str);
return $str;
}


echo AddLink2Text("https://tw.yahoo.com/");

?>

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()