ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
Length.php
Go to the documentation of this file.
1 <?php
2 
11 {
12 
13  public function validate($string, $config, $context) {
14 
15  $string = trim($string);
16  if ($string === '') return false;
17 
18  $parent_result = parent::validate($string, $config, $context);
19  if ($parent_result !== false) return $parent_result;
20 
21  $length = strlen($string);
22  $last_char = $string[$length - 1];
23 
24  if ($last_char !== '%') return false;
25 
26  $points = substr($string, 0, $length - 1);
27 
28  if (!is_numeric($points)) return false;
29 
30  $points = (int) $points;
31 
32  if ($points < 0) return '0%';
33  if ($points > 100) return '100%';
34 
35  return ((string) $points) . '%';
36 
37  }
38 
39 }
40 
41 // vim: et sw=4 sts=4
Validates an integer representation of pixels according to the HTML spec.
Definition: Pixels.php:6
Validates the HTML type length (not to be confused with CSS&#39;s length).
Definition: Length.php:10
validate($string, $config, $context)
Definition: Length.php:13