require_once("Zend/Loader.php");
//Introducing the validator class and the functional class (Int) of the validator, and the custom interface class;
Zend_Loader::loadClass('Zend_Validate');
Zend_Loader::loadClass('Zend_Validate_Int' ; Declare the error message reporting attribute in the interface
protected $_messages = array();
//Declare the verification method in the interface
public function isValid($num)
{
if ( !($num%3==0) && !($num%5==0))
{
//If the verification fails, the error message return value is given to the error message reporting attribute
$this -> _messages[] = "The value you entered is not a common multiple of 3 and 5!";
// Terminate the program
return false;
}
//Return true
return true;
}
//Define the error reporting method of the interface
public function getMessages()
{
return $this -> _messages;
}
// Define extraction error information (optional)
public function getErrors()
{
}
}
//External definition of common multiple detection method
function check_num($num){
//Instantiate the validator class
$Validate = new Zend_Validate();
//Add validator function class, add custom validator function class, form a validator chain
$Validate -> addValidator(new Zend_Validate_Int())
- > addValidator(new GongBeiNum());
//Validation parameters
if (!$Validate -> isValid($num))
{
//If there is an error, loop the error message and Output
foreach ($Validate -> getMessages() as $value)
{
echo $value . "
";
return false;
}
}
}
//Specify the judgment value
$num1 = '15';
//Run the verification method
check_num($num1);
?>