|
function validateEmail($email)
{ return eregi("^[_a-z0-9-]+(/.[_a-z0-9-]+)*@[a-z0-9-]+(/.[a-z0-9-]+)*(/.[a-z]{2,3})$", $email);
}
function validateURL($url)
{ return eregi("^((ht|f)tp://)((([a-z0-9-]+(/.[a-z0-9-]+)*(/.[a-z]{2,3}))|(([0-9]{1,3}/.){3}([0-9]{1,3})))((/|/?)[a-z0-9~#%&'_/+=:/?/.-]*)*)$", $url);
}
function convertURLS($text)
{ $text = eregi_replace("((ht|f)tp://www/.|www/.)([a-z0-9-]+(/.[a-z0-9-]+)*(/.[a-z]{2,3})((/|/?)[a-z0-9~#%&///'_/+=:/?/.-]*)*)", "http://www.//3", $text);
$text = eregi_replace("((ht|f)tp://)((([a-z0-9-]+(/.[a-z0-9-]+)*(/.[a-z]{2,3}))|(([0-9]{1,3}/.){3}([0-9]{1,3})))((/|/?)[a-z0-9~#%&'_/+=:/?/.-]*)*)", "<a href=/"//0/">//0</a>", $text);
return $text;
}
function convertMail($text)
{ $text = eregi_replace("([_a-z0-9-]+(/.[_a-z0-9-]+)*@[a-z0-9-]+(/.[a-z0-9-]+)*(/.[a-z]{2,3}))", "<a href='mailto://0'>//0</a>", $text);
return $text;
}
function convertAllLinks($text)
{ $text = convertURLS($text);
$text = convertMail($text);
return $text;
}
?>
php技術:Email+URL的判斷和自動轉換函數,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。