Source for file Length.php

Documentation is available at Length.php

  1. <?php
  2.  
  3. /**
  4.  * Validates the HTML type length (not to be confused with CSS's length).
  5.  * 
  6.  * This accepts integer pixels or percentages as lengths for certain
  7.  * HTML attributes.
  8.  */
  9.  
  10. {
  11.     
  12.     public function validate($string$config$context{
  13.         
  14.         $string trim($string);
  15.         if ($string === ''return false;
  16.         
  17.         $parent_result parent::validate($string$config$context);
  18.         if ($parent_result !== falsereturn $parent_result;
  19.         
  20.         $length strlen($string);
  21.         $last_char $string[$length 1];
  22.         
  23.         if ($last_char !== '%'return false;
  24.         
  25.         $points substr($string0$length 1);
  26.         
  27.         if (!is_numeric($points)) return false;
  28.         
  29.         $points = (int) $points;
  30.         
  31.         if ($points 0return '0%';
  32.         if ($points 100return '100%';
  33.         
  34.         return ((string) $points'%';
  35.         
  36.     }
  37.     
  38. }

Documentation generated on Thu, 19 Jun 2008 18:49:42 -0400 by phpDocumentor 1.4.2