4 * Validates the HTML type length (not to be confused with CSS's length).
6 * This accepts integer pixels or percentages as lengths for certain
10 class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
14 * @param string $string
15 * @param HTMLPurifier_Config $config
16 * @param HTMLPurifier_Context $context
19 public function validate($string, $config, $context)
21 $string = trim($string);
26 $parent_result = parent::validate($string, $config, $context);
27 if ($parent_result !== false) {
28 return $parent_result;
31 $length = strlen($string);
32 $last_char = $string[$length - 1];
34 if ($last_char !== '%') {
38 $points = substr($string, 0, $length - 1);
40 if (!is_numeric($points)) {
44 $points = (int)$points;
52 return ((string)$points) . '%';