33 public function validate($string, $config, $context)
35 $length = strlen($string);
45 if ($length > 1 && $string[0] ===
'[' && $string[$length - 1] ===
']') {
47 $ip = substr($string, 1, $length - 2);
48 $valid = $this->ipv6->validate($ip, $config, $context);
56 $ipv4 = $this->ipv4->validate($string, $config, $context);
57 if (
$ipv4 !==
false) {
77 $underscore = $config->get(
'Core.AllowHostnameUnderscore') ?
'_' :
'';
82 $and =
"[a-z0-9-$underscore]";
84 $domainlabel =
"$an($and*$an)?";
86 $toplabel =
"$a($and*$an)?";
88 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
96 if ($config->get(
'Core.EnableIDNA')) {
97 $idna =
new Net_IDNA2(array(
'encoding' =>
'utf8',
'overlong' =>
false,
'strict' =>
true));
99 $parts = explode(
'.', $string);
101 $new_parts = array();
102 foreach ($parts as $part) {
104 for ($i = 0, $c = strlen($part); $i < $c; $i++) {
105 if (ord($part[$i]) > 0x7a) {
111 $new_parts[] = $part;
113 $new_parts[] = $idna->encode($part);
116 $string = implode(
'.', $new_parts);
117 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {