答案:<?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://www\.www\.)([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})((/\?)[a-z0-9~#%&\\/'_\+=:\?\.-]*)*)", "http://www.\\3", $text);
$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=> 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=> return $text;
}
function convertAllLinks($text)
{ $text = convertURLS($text);
$text = convertMail($text);
return $text;
}
?>
上一个:Excel到mysql的转化(PHP二十行语句实现)
下一个:PHP用cookies来跟踪识别用户