如何将其转换为preg_match?
$urlregex = "(https?|ftp)://([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&;%$-]+)*@)*((?:(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9])\.){3}(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9]|0)|localhost|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:\d+)*(($|[a-zA-Z0-9.,?'+\\&;%\$#=~_-]+))*";
if (!eregi($urlregex, $_POST['url'])) {
$error = true;
$res = array(
'response' => 'error',
'message' => 'The URL you have entered is invalid.'
);
}
答案 0 :(得分:2)
更好地使用build in URL validation。
if (filter_var(urldecode($_POST['url']), FILTER_VALIDATE_URL) == FALSE) {
$error = true;
$res = array(
'response' => 'error',
'message' => 'The URL you have entered is invalid.'
);
}