我一直在嘗試讓這段代碼工作很長一段時間,我仍然得到相同的錯誤。 任何幫助將是偉大的。在php驗證解析錯誤
錯誤代碼
Parse error: syntax error, unexpected ';' in /home/ob219/public_html/membership/classes/Validate.php on line 38
代碼
<?php
class Validate {
private $_passed = false,
$_errors = array(),
$_db = null;
public function __construct() {
$this->_db = DB::getInstance();
}
public function check($source, $items = array()) {
foreach($items as $item => $rules) {
foreach($rules as $rule => $rule_value) {
$value = trim($source[$item]);
$item = escape($item);
if($rule == 'required' && empty($value)) {
$this->addError("{$item} is required");
} else if(!empty($value)) {
switch($rule) {
case 'min':
if(strlen($value) < $rule_value) {
$this->addError("{$item} must be a minimum of {$rule_value} characters.");
}
break;
case 'max':
if(strlen($value) > $rule_value) {
$this->addError("{$item} must be a maximum of {$rule_value} characters.");
}
break;
case 'matches':
if($value != $source [$rule_value]) {
$this->addError("{$rule_value} must match {$item}");
}
break;
case 'unique':
$check = $this->_db->get($rule_value, array($item, '=', $value);
if($check->count()) {
$this->addError("{$item} already exists.");
}
break;
}
}
}
}
if(empty($this->_errors)) {
$this->_passed = true;
}
return $this;
}
private function addError($error) {
$this->_errors[] = $error;
}
public function errors() {
return $this->_errors;
}
public function passed() {
return $this->_passed;
}
}
好,這是第38行? – Doorknob
@Jessica im使用崇高的文字2,你能推薦一個更好的嗎? – Beep
PHPStorm,Eclipse,Zend Studio,Visual Studio,天空是極限。儘管我所命名的所有東西都是更好的選擇。 – skrilled