4 * Validates a color according to the HTML spec.
6 class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
10 * @param string $string
11 * @param HTMLPurifier_Config $config
12 * @param HTMLPurifier_Context $context
15 public function validate($string, $config, $context)
17 static $colors = null;
18 if ($colors === null) {
19 $colors = $config->get('Core.ColorKeywords');
22 $string = trim($string);
27 $lower = strtolower($string);
28 if (isset($colors[$lower])) {
29 return $colors[$lower];
31 if ($string[0] === '#') {
32 $hex = substr($string, 1);
37 $length = strlen($hex);
38 if ($length !== 3 && $length !== 6) {
41 if (!ctype_xdigit($hex)) {
45 $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];