Pogledajte određenu poruku
Staro 27. 01. 2013.   #11
webarto
expert
Grand Master
 
Avatar webarto
 
Datum učlanjenja: 11.04.2010
Poruke: 998
Hvala: 141
959 "Hvala" u 153 poruka
webarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished road
Default



PHP kôd:
class Validator
{

  public function 
process()
  {
    if (
strpos($rules'min=') !== false)
    {
      
$num $this->min($var$rules);
      if (
is_numeric($num))
      {
        
$this->errors[] = "should have at least $num characters!";
      } elseif (
$num === false)
      {
        
$this->errors[] = 'Invalid rule.';
      }
    }
  }
  
  private function 
min($var$rules)
  {
    
preg_match('%min=([0-9]{1,10})%'$rules$matches);
    if (empty(
$matches[1]))
      return 
false;
    return 
strlen($var) < (int)$matches[1] ? $matches[1] : true;
  }

}

$validator = (new Validator($vars))->process(); 
Ovako nešto, nadam se da shvataš.
__________________
Github // LinkedIn // PHP // ZCE // Stackoverflow PHP // Site5 Web Hosting

Poslednja izmena od webarto : 27. 01. 2013. u 15:35.
webarto je offline   Odgovorite uz citat
"Hvala" webarto za poruku: