不会吧?
<?
function autourl($messagetext)
{
//-----自动URL-----------
$urlSearchArray = array(
"/([^]_a-z0-9-=\"'\/])((https?|ftp|rtsp|mms|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)\b/si",
"/^((https?|ftp|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)\b/si"
);
$urlReplaceArray = array(
"\\1\\2\\4",
"\\1\\3"
);
$emailSearchArray = array(
"/([ \n\r\t])([\\._a-zA-Z0-9-]+(\.[\\._a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3}))/si",
"/^([\\._a-zA-Z0-9-]+(\.[\\._a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3}))/si" ); $emailReplaceArray = array(
"\\1\\2",
"\\0"
); $text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
if (strpos($text, "@")) {
$text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
}
return $text;
}
echo autourl("http://bbs.soulsky.net测试");
?>
输出
http://bbs.soulsky.net测试
<?
function autourl($messagetext)
{
//-----自动URL-----------
$urlSearchArray = array(
"/([^]_a-z0-9-=\"'\/])((https?|ftp|rtsp|mms|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)\b/si",
"/^((https?|ftp|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)\b/si"
);
$urlReplaceArray = array(
"\\1\\2\\4",
"\\1\\3"
);
$emailSearchArray = array(
"/([ \n\r\t])([\\._a-zA-Z0-9-]+(\.[\\._a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3}))/si",
"/^([\\._a-zA-Z0-9-]+(\.[\\._a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3}))/si" ); $emailReplaceArray = array(
"\\1\\2",
"\\0"
); $text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
if (strpos($text, "@")) {
$text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
}
return $text;
}
echo autourl("http://bbs.soulsky.net测试");
?>
输出
http://bbs.soulsky.net测试
"/([^]_a-z0-9-=\"'\/])((https?|ftp|rtsp|mms|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si",
"/^((https?|ftp|gopher|news|telnet):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si"
);
这个的/si前面加了一个\b吧
例:
另外,为什么email未被分析呢?