1
我正在根據表單值創建一個正則表達式數組,並使用錯誤的用戶輸入失敗的函數。我每次運行的網站,我收到以下錯誤:使用正則表達式數組進行PHP驗證
警告: eregi()[function.eregi]:REG_EMPTY
我不知道什麼是錯。請看看我的代碼和幫助。謝謝!
$error_log = array();
// Checks if user inputed data matches the default values
$arr = array(
'name' => 'First Name Last Name',
'month' => 'MM',
'day' => 'DD',
'year' => 'YYYY',
'address1' =>'Address Line 1',
'address2' => 'Address Line 2',
'email' => '[email protected]'
);
$regex = array(
'name' => "^[a-z .'-]+$",
'month' => "^((0[1-9])|(1[0-2]))$ ",
'day' => "0?[1-9]|[1-2][0-9]|3[0-1]",
'year' => "^(19|20)\d{2}$",
'address1' => "/^[a-zA-Z0-9 ]*$/",
'address2' => "/^[a-zA-Z0-9 ]*$/",
'email' => "^[A-Z0-9._%-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$"
);
/*
Runs validation on the form values and stops procesing if the form does not have the correct values
*/
function regexValidate($form_value, $regex, $key){
if(!eregi($regex[$key],$form_value)){
return true;
}
return false;
}
*(阿里納斯)就可以擴大*由於PHP的5.3.0,`eregi`不贊成使用[PCRE擴展](http://de2.php.net/manual/en/book.pcre.php)。調用這個函數將發出一個`E_DEPRECATED`通知。查看[差異列表](http://de2.php.net/manual/en/reference.pcre.pattern.posix.php)以獲得轉換爲PCRE的幫助。 – Gordon 2011-02-14 16:40:04
我建議你嘗試輸出`$ key`和`$ regex [$ key]`來查看你正在嘗試使用哪個正則表達式。如果在那裏有問題(比如說,一個意外的鍵值),你將得到一個null regex饋給eregi(),導致你的錯誤。正如戈登指出的那樣,eregi()已被棄用。我認爲preg_match()將是一個更好的選擇。 – 2011-02-14 16:40:12