25 $length = strlen($string);
32 if ($string ===
'')
return '';
33 if ($length > 1 && $string[0] ===
'[' && $string[$length-1] ===
']') {
35 $ip = substr($string, 1, $length - 2);
36 $valid = $this->ipv6->validate($ip,
$config, $context);
37 if ($valid ===
false)
return false;
38 return '['. $valid .
']';
42 $ipv4 = $this->ipv4->validate($string,
$config, $context);
55 $domainlabel =
"$an($and*$an)?";
57 $toplabel =
"$a($and*$an)?";
59 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
67 if (
$config->get(
'Core.EnableIDNA')) {
68 $idna =
new Net_IDNA2(array(
'encoding' =>
'utf8',
'overlong' =>
false,
'strict' =>
true));
70 $parts = explode(
'.', $string);
73 foreach ($parts as $part) {
75 for (
$i = 0, $c = strlen($part);
$i < $c;
$i++) {
76 if (ord($part[
$i]) > 0x7a) {
84 $new_parts[] = $idna->encode($part);
87 $string = implode(
'.', $new_parts);
88 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
91 }
catch (Exception $e) {