欢迎光临第一亲子网

Email+URL的判断和自动转换函数

2013-9-2 | 来源:第一亲子网 | 点击:

导读: ...

PHP
function validateEmail($email)牋
{牋牋爎eturn eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email);牋
}牋

function validateURL($url)牋
{牋牋爎eturn 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~#%&'_+=:?.-]*)*)", "\0", $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}))", "\0", $text);牋
牋牋return $text;牋
}牋

function convertAllLinks($text)牋
{牋牋$text = convertURLS($text);牋
牋牋$text = convertMail($text);牋
牋牋return $text;牋
}
?>牋

上一篇:用函数读出数据表内容放入二维数

下一篇:一个高ai的分页函数和一个url函数