ipv4 = new HTMLPurifier_AttrDef_URI_IPv4(); $this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6(); } function validate($string, $config, &$context) { $length = strlen($string); if ($string === '') return ''; if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') { //IPv6 $ip = substr($string, 1, $length - 2); $valid = $this->ipv6->validate($ip, $config, $context); if ($valid === false) return false; return '['. $valid . ']'; } // need to do checks on unusual encodings too $ipv4 = $this->ipv4->validate($string, $config, $context); if ($ipv4 !== false) return $ipv4; // validate a domain name here, do filtering, etc etc etc // We could use this, but it would break I18N domain names //$match = preg_match('/^[a-z0-9][\w\-\.]*[a-z0-9]$/i', $string); //if (!$match) return false; return $string; } }