Email+URL的判断和自动转换函数
2018-09-07 12:45
<?php
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("^((htf)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("((htf)tp://
$text = eregi_replace("((htf)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;
}
?>
文章标题:Email+URL的判断和自动转换函数
文章链接:http://soscw.com/index.php/essay/12145.html