2012-07-03 68 views
0

如何將其轉換爲preg_match?如何將eregi轉換爲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

[轉換額日格則表達式來浸漬料]的可能重複(http://stackoverflow.com/questions/6270004/converting-ereg-expressions-to-preg) – nickb

+0

我曾嘗試: /^ $ urlregex /我總是給我未知的修飾語錯誤。我不知道這個錯誤。 – Bonfocchi

回答

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.' 
    ); 
}