• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Net_IDNA2类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Net_IDNA2的典型用法代码示例。如果您正苦于以下问题:PHP Net_IDNA2类的具体用法?PHP Net_IDNA2怎么用?PHP Net_IDNA2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Net_IDNA2类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: decode

 /**
  * Decodes punycoded'd URL
  * @param  string $url URL
  * @return mixed  string with decoded URL on success, boolean false otherwise
  */
 public static function decode($url)
 {
     $url = self::fix($url);
     if ($url) {
         $components = parse_url($url);
         $host = $components['host'];
         if (strpos($host, self::PUNYCODE_PREFIX) !== false) {
             $idn = new \Net_IDNA2();
             $host = $idn->decode($host);
         }
         $path = !empty($components['path']) ? $components['path'] : '';
         return $host . rtrim($path, '/');
     }
     return false;
 }
开发者ID:OneataBogdan,项目名称:lead_coriolan,代码行数:20,代码来源:Url.php


示例2: idn_to_ascii

 function idn_to_ascii($domain, $options = 0, $variant = INTL_IDNA_VARIANT_2003, &$idna_info = null)
 {
     if ($domain && preg_match('/[^\\x20-\\x7E]/', $domain)) {
         if ($variant == INTL_IDNA_VARIANT_2003) {
             $idn = Net_IDNA2::singleton(array('encoding' => 'utf8', 'version' => '2003', 'overlong' => false));
         } else {
             $idn = Net_IDNA2::singleton(array('encoding' => 'utf8', 'version' => '2008', 'overlong' => false));
         }
         try {
             $domain = $idn->encode($domain);
         } catch (Exception $e) {
         }
     }
     return $domain;
 }
开发者ID:patilstar,项目名称:HMVC-WITH-CI,代码行数:15,代码来源:idn.php


示例3: encodeIDN

 /**
  * Converts given IDN to the punycode.
  * @param string $value IDN to be converted.
  * @return string resulting punycode.
  * @since 1.1.13
  */
 private function encodeIDN($value)
 {
     if (preg_match_all('/^(.*)@(.*)$/', $value, $matches)) {
         if (function_exists('idn_to_ascii')) {
             $value = $matches[1][0] . '@' . idn_to_ascii($matches[2][0]);
         } else {
             require_once Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net') . DIRECTORY_SEPARATOR . 'IDNA2.php';
             $idna = new Net_IDNA2();
             $value = $matches[1][0] . '@' . @$idna->encode($matches[2][0]);
         }
     }
     return $value;
 }
开发者ID:blackdragon199154,项目名称:scryptmail,代码行数:19,代码来源:CEmailValidator.php


示例4: dirname

<?php

// Platform's core initialization.
require dirname(__FILE__) . '/../config.php';
require $PLATFORMCREATE;
ci()->load->helper('url')->library('template');
header('Content-Type: text/html; charset=UTF-8');
//require 'Net/IDNA2.php';
$idn = Net_IDNA2::getInstance();
if (isset($_REQUEST['encode'])) {
    $decoded = isset($_REQUEST['decoded']) ? $_REQUEST['decoded'] : '';
    try {
        $encoded = $idn->encode($decoded);
    } catch (Exception $e) {
        /* just swallow */
    }
}
if (isset($_REQUEST['decode'])) {
    $encoded = isset($_REQUEST['encoded']) ? $_REQUEST['encoded'] : '';
    try {
        $decoded = $idn->decode($encoded);
    } catch (Exception $e) {
        /* just swallow */
    }
}
if (!isset($encoded)) {
    $encoded = '';
}
if (!isset($decoded)) {
    $decoded = '';
}
开发者ID:Qnatz,项目名称:starter-public-edition-4,代码行数:31,代码来源:idna.php


示例5: singleton

 /**
  * Attempts to return a concrete IDNA instance for either php4 or php5,
  * only creating a new instance if no IDNA instance with the same
  * parameters currently exists.
  *
  * @param array $params Set of paramaters
  *
  * @return object Net_IDNA2
  * @access public
  */
 function singleton($params = array())
 {
     static $instances;
     if (!isset($instances)) {
         $instances = array();
     }
     $signature = serialize($params);
     if (!isset($instances[$signature])) {
         $instances[$signature] = Net_IDNA2::getInstance($params);
     }
     return $instances[$signature];
 }
开发者ID:mover5,项目名称:imobackup,代码行数:22,代码来源:IDNA2.php


示例6: dirname

if (file_exists(dirname(__FILE__) . "/../../../init.php")) {
    require_once dirname(__FILE__) . "/../../../init.php";
} else {
    require_once dirname(__FILE__) . "/../../../dbconnect.php";
}
require_once dirname(__FILE__) . "/../../../includes/functions.php";
require_once dirname(__FILE__) . "/../../../includes/registrarfunctions.php";
require_once dirname(__FILE__) . "/namecheapapi.php";
$registrar = "namecheap";
$params = getregistrarconfigoptions($registrar);
$testmode = (bool) $params['TestMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$sync_next_due_date = (bool) $params['SyncNextDueDate'];
$idna2 = new Net_IDNA2();
$report = "Namecheap Domain Sync Report\n" . "-----------------------------------------------------------------------------------------------------\n\n";
/**
 * Transfers
 */
$report .= "Processing transfers:\n";
$dbresult = select_query("tbldomains", "id, LOWER(domain) AS domain", array('registrar' => $registrar, 'status' => "Pending Transfer"));
if (!$dbresult || !mysql_num_rows($dbresult)) {
    $report .= "No domains with status 'Pending Transfer' found\n";
} else {
    $transfers = array();
    try {
        $request_params = array('ListType' => "COMPLETED", 'PageSize' => 100, 'SortBy' => "DOMAINNAME");
        if (!empty($params['PromotionCode'])) {
            $request_params['PromotionCode'] = $params['PromotionCode'];
        }
开发者ID:billyprice1,项目名称:whmcs,代码行数:30,代码来源:namecheapsync.php


示例7: validate

 public function validate($string, $config, $context)
 {
     $length = strlen($string);
     // empty hostname is OK; it's usually semantically equivalent:
     // the default host as defined by a URI scheme is used:
     //
     //      If the URI scheme defines a default for host, then that
     //      default applies when the host subcomponent is undefined
     //      or when the registered name is empty (zero length).
     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;
     }
     // A regular domain name.
     // This doesn't match I18N domain names, but we don't have proper IRI support,
     // so force users to insert Punycode.
     // The productions describing this are:
     $a = '[a-z]';
     // alpha
     $an = '[a-z0-9]';
     // alphanum
     $and = '[a-z0-9-]';
     // alphanum | "-"
     // domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
     $domainlabel = "{$an}({$and}*{$an})?";
     // toplabel    = alpha | alpha *( alphanum | "-" ) alphanum
     $toplabel = "{$a}({$and}*{$an})?";
     // hostname    = *( domainlabel "." ) toplabel [ "." ]
     if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
         return $string;
     }
     // If we have Net_IDNA2 support, we can support IRIs by
     // punycoding them. (This is the most portable thing to do,
     // since otherwise we have to assume browsers support
     if ($config->get('Core.EnableIDNA')) {
         $idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
         // we need to encode each period separately
         $parts = explode('.', $string);
         try {
             $new_parts = array();
             foreach ($parts as $part) {
                 $encodable = false;
                 for ($i = 0, $c = strlen($part); $i < $c; $i++) {
                     if (ord($part[$i]) > 0x7a) {
                         $encodable = true;
                         break;
                     }
                 }
                 if (!$encodable) {
                     $new_parts[] = $part;
                 } else {
                     $new_parts[] = $idna->encode($part);
                 }
             }
             $string = implode('.', $new_parts);
             if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
                 return $string;
             }
         } catch (Exception $e) {
             // XXX error reporting
         }
     }
     return false;
 }
开发者ID:SallyU,项目名称:yiicms,代码行数:77,代码来源:HTMLPurifier.standalone.php


示例8: isValid

 /**
  * Check valid url
  *
  * @param string $url
  * @return bool
  */
 public static function isValid($url)
 {
     if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
         return true;
     }
     try {
         $idn = new \Net_IDNA2();
         $url = $idn->encode($url);
         if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
             return true;
         }
     } catch (\InvalidArgumentException $e) {
     }
     return false;
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:21,代码来源:Url.php


示例9: encodeIDN

 /**
  * Converts given IDN to the punycode.
  *
  * @param string $value IDN to be converted.
  *
  * @return string resulting punycode.
  * @since 1.1.13
  */
 private function encodeIDN($value)
 {
     if (preg_match_all('/^(.*)@(.*)$/', $value, $matches)) {
         if (function_exists('idn_to_ascii')) {
             $value = $matches[1][0] . '@' . idn_to_ascii($matches[2][0]);
         } else {
             require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Net_IDNA2' . DIRECTORY_SEPARATOR . 'IDNA2.php';
             $idna = new Net_IDNA2();
             $value = $matches[1][0] . '@' . @$idna->encode($matches[2][0]);
         }
     }
     return $value;
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:21,代码来源:EmailValidator.php


示例10: decodePunycode

 /**
  * Retrieve decoding domain name from punycode
  *
  * @param string $url decode url from Punycode
  * @return string
  */
 public function decodePunycode($url)
 {
     $parsedUrl = parse_url($url);
     if ($this->_isPunycode($parsedUrl['host'])) {
         if (function_exists('idn_to_utf8')) {
             $host = idn_to_utf8($parsedUrl['host']);
         } else {
             $idn = new Net_IDNA2();
             $host = $idn->decode($parsedUrl['host']);
         }
         return str_replace($parsedUrl['host'], $host, $url);
     } else {
         return $url;
     }
 }
开发者ID:tesorogithub,项目名称:tesoroshop,代码行数:21,代码来源:__default.php


示例11: validate

 public function validate($string, $config, $context)
 {
     $length = strlen($string);
     if ($string === '') {
         return '';
     }
     if ($length > 1 && $string[0] === '[' && $string[$length - 1] === ']') {
         $ip = substr($string, 1, $length - 2);
         $valid = $this->ipv6->validate($ip, $config, $context);
         if ($valid === false) {
             return false;
         }
         return '[' . $valid . ']';
     }
     $ipv4 = $this->ipv4->validate($string, $config, $context);
     if ($ipv4 !== false) {
         return $ipv4;
     }
     $underscore = $config->get('Core.AllowHostnameUnderscore') ? '_' : '';
     $a = '[a-z]';
     $an = '[a-z0-9]';
     $and = "[a-z0-9-{$underscore}]";
     $domainlabel = "{$an}({$and}*{$an})?";
     $toplabel = "{$a}({$and}*{$an})?";
     if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
         return $string;
     }
     if ($config->get('Core.EnableIDNA')) {
         $idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
         $parts = explode('.', $string);
         try {
             $new_parts = array();
             foreach ($parts as $part) {
                 $encodable = false;
                 for ($i = 0, $c = strlen($part); $i < $c; $i++) {
                     if (ord($part[$i]) > 0x7a) {
                         $encodable = true;
                         break;
                     }
                 }
                 if (!$encodable) {
                     $new_parts[] = $part;
                 } else {
                     $new_parts[] = $idna->encode($part);
                 }
             }
             $string = implode('.', $new_parts);
             if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
                 return $string;
             }
         } catch (Exception $e) {
         }
     }
     return false;
 }
开发者ID:harrylongworth,项目名称:tv-bb,代码行数:55,代码来源:HTMLPurifier.standalone.php


示例12: decode_host

/**
 * Decodes from punycode
 * @param string $host ONLY the host name, e.g. "XN----7SBCPNF2DL2EYA.XN--P1AI"
 * @return string
 */
function decode_host($host)
{
    if (stripos($host, "xn--") === false) {
        return $host;
    }
    require_once 'Net/IDNA2.php';
    // netcat/require/lib
    $decoder = new Net_IDNA2();
    try {
        $host = $decoder->decode(strtolower($host));
    } catch (Net_IDNA2_Exception $e) {
        trigger_error("Cannot convert host name '{$host}' from punycode: {$e->getMessage()}", E_USER_WARNING);
        return $host;
    }
    return $host;
}
开发者ID:Blu2z,项目名称:implsk,代码行数:21,代码来源:s_common.inc.php


示例13: encode_idna

/**
 * Encodes a String from IDNA format ASCII
 *
 * @param  $input
 * @return string
 */
function encode_idna($input)
{
    if (function_exists('idn_to_ascii')) {
        return idn_to_ascii($input);
    } else {
        $IDNA = new Net_IDNA2();
        $output = $IDNA->encode($input);
        return $output;
    }
}
开发者ID:gOOvER,项目名称:EasySCP,代码行数:16,代码来源:easyscp-functions.php


示例14: _addAddress

 /**
  * Does a bunch of additional validation on the email address parts contained in $emailAddress
  *  Then adds it to $emailAdddresses.
  */
 private function _addAddress(&$emailAddresses, &$emailAddress, $encoding)
 {
     if (!$emailAddress['invalid']) {
         if ($emailAddress['address_temp'] || $emailAddress['quote_temp']) {
             $emailAddress['invalid'] = true;
             $emailAddress['invalid_reason'] = "Incomplete address";
             $this->log('error', "Email\\Parse->_addAddress - corruption during parsing - leftovers:\n\$i: {$i}\n\$emailAddress['address_temp'] : {$emailAddress['address_temp']}\n\$emailAddress['quote_temp']: {$emailAddress['quote_temp']}\n");
         } elseif ($emailAddress['ip'] && $emailAddress['domain']) {
             // Error - this should never occur
             $emailAddress['invalid'] = true;
             $emailAddress['invalid_reason'] = "Confusion during parsing";
             $this->log('error', "Email\\Parse->_addAddress - both an IP address '{$emailAddress['ip']}' and a domain '{$emailAddress['domain']}' found for the email address '{$emailAddress['original_address']}'\n");
         } elseif ($emailAddress['ip'] || $emailAddress['domain'] && preg_match('/\\d+\\.\\d+\\.\\d+\\.\\d+/', $emailAddress['domain'])) {
             if ($emailAddress['domain']) {
                 $emailAddress['ip'] = $emailAddress['domain'];
                 $emailAddress['domain'] = null;
             }
             if (!$this->ipValidator) {
                 $this->ipValidator = new Ip();
             }
             try {
                 if (!$this->ipValidator->isValid($emailAddress['ip'])) {
                     $emailAddress['invalid'] = true;
                     $emailAddress['invalid_reason'] = 'IP address invalid: \'' . $emailAddress['ip'] . '\' does not appear to be a valid IP address';
                 } elseif (preg_match('/192\\.168\\.\\d+\\.\\d+/', $emailAddress['ip']) || preg_match('/172\\.(1[6-9]|2[0-9]|3[0-2])\\.\\d+\\.\\d+/', $emailAddress['ip']) || preg_match('/10\\.\\d+\\.\\d+\\.\\d+/', $emailAddress['ip'])) {
                     $emailAddress['invalid'] = true;
                     $emailAddress['invalid_reason'] = 'IP address invalid (private): ' . $emailAddress['ip'];
                 } elseif (preg_match('/169\\.254\\.\\d+\\.\\d+/', $emailAddress['ip'])) {
                     $emailAddress['invalid'] = true;
                     $emailAddress['invalid_reason'] = 'IP address invalid (APIPA): ' . $emailAddress['ip'];
                 }
             } catch (Exception $e) {
                 $emailAddress['invalid'] = true;
                 $emailAddress['invalid_reason'] = 'IP address invalid: ' . $emailAddress['ip'];
             }
         } elseif ($emailAddress['domain']) {
             // Check for IDNA
             if (max(array_keys(count_chars($emailAddress['domain'], 1))) > 127) {
                 $idna = new \Net_IDNA2();
                 try {
                     $emailAddress['domain'] = $idna->encode($emailAddress['domain']);
                 } catch (Exception $e) {
                     $emailAddress['invalid'] = true;
                     $emailAddress['invalid_reason'] = "Can't convert domain {$emailAddress['domain']} to punycode";
                 }
             }
             $result = $this->validateDomainName($emailAddress['domain']);
             if (!$result['valid']) {
                 $emailAddress['invalid'] = true;
                 $emailAddress['invalid_reason'] = isset($result['reason']) ? 'Domain invalid: ' . $result['reason'] : 'Domain invalid for some unknown reason';
             }
         }
     }
     // Prepare some of the fields needed
     $emailAddress['name_parsed'] = rtrim($emailAddress['name_parsed']);
     $emailAddress['original_address'] = rtrim($emailAddress['original_address']);
     $name = $emailAddress['name_quoted'] ? "\"{$emailAddress['name_parsed']}\"" : $emailAddress['name_parsed'];
     $localPart = $emailAddress['local_part_quoted'] ? "\"{$emailAddress['local_part_parsed']}\"" : $emailAddress['local_part_parsed'];
     $domainPart = $emailAddress['ip'] ? '[' . $emailAddress['ip'] . ']' : $emailAddress['domain'];
     if (!$emailAddress['invalid']) {
         if (mb_strlen($domainPart, $encoding) == 0) {
             $emailAddress['invalid'] = true;
             $emailAddress['invalid_reason'] = 'Email address needs a domain after the \'@\'';
         } elseif (mb_strlen($localPart, $encoding) > 63) {
             $emailAddress['invalid'] = true;
             $emailAddress['invalid_reason'] = 'Email address before the \'@\' can not be greater than 63 characters';
         } elseif (mb_strlen($localPart, $encoding) + mb_strlen($domainPart, $encoding) + 1 > 254) {
             $emailAddress['invalid'] = true;
             $emailAddress['invalid_reason'] = 'Email addresses can not be greater than 254 characters';
         }
     }
     // Build the email address hash
     $emailAddrDef = array('address' => '', 'simple_address' => '', 'original_address' => rtrim($emailAddress['original_address']), 'name' => $name, 'name_parsed' => $emailAddress['name_parsed'], 'local_part' => $localPart, 'local_part_parsed' => $emailAddress['local_part_parsed'], 'domain_part' => $domainPart, 'domain' => $emailAddress['domain'], 'ip' => $emailAddress['ip'], 'invalid' => $emailAddress['invalid'], 'invalid_reason' => $emailAddress['invalid_reason']);
     // Build the proper address by hand (has comments stripped out and should have quotes in the proper places)
     if (!$emailAddrDef['invalid']) {
         $emailAddrDef['simple_address'] = "{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}";
         $properAddress = $emailAddrDef['name'] ? "{$emailAddrDef['name']} <{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}>" : $emailAddrDef['simple_address'];
         $emailAddrDef['address'] = $properAddress;
     }
     $emailAddresses[] = $emailAddrDef;
     return $emailAddrDef['invalid'];
 }
开发者ID:oodle,项目名称:email-parse,代码行数:86,代码来源:Parse.php


示例15: idn_to_ascii

 function idn_to_ascii($domain)
 {
     static $idn, $loaded;
     if (!$loaded) {
         $idn = new Net_IDNA2();
         $loaded = true;
     }
     if ($idn && $domain && preg_match('/[^\\x20-\\x7E]/', $domain)) {
         try {
             $domain = $idn->encode($domain);
         } catch (Exception $e) {
         }
     }
     return $domain;
 }
开发者ID:NathanAUS,项目名称:roundcubemail,代码行数:15,代码来源:bootstrap.php


示例16: decodeIDN

 /**
  * Converts given punycode to the IDN.
  * @param string $value punycode to be converted.
  * @return string resulting IDN.
  * @since 1.1.13
  */
 private function decodeIDN($value)
 {
     if (preg_match_all('/^(.*):\\/\\/([^\\/]+)(.*)$/', $value, $matches)) {
         if (function_exists('idn_to_utf8')) {
             $value = $matches[1][0] . '://' . idn_to_utf8($matches[2][0]) . $matches[3][0];
         } else {
             require_once Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net') . DIRECTORY_SEPARATOR . 'IDNA2.php';
             $idna = new Net_IDNA2();
             $value = $matches[1][0] . '://' . @$idna->decode($matches[2][0]) . $matches[3][0];
         }
     }
     return $value;
 }
开发者ID:azizbekvahidov,项目名称:foods,代码行数:19,代码来源:CUrlValidator.php


示例17: validate

 /**
  * @param string $string
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return bool|string
  */
 public function validate($string, $config, $context)
 {
     $length = strlen($string);
     // empty hostname is OK; it's usually semantically equivalent:
     // the default host as defined by a URI scheme is used:
     //
     //      If the URI scheme defines a default for host, then that
     //      default applies when the host subcomponent is undefined
     //      or when the registered name is empty (zero length).
     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;
     }
     // A regular domain name.
     // This doesn't match I18N domain names, but we don't have proper IRI support,
     // so force users to insert Punycode.
     // There is not a good sense in which underscores should be
     // allowed, since it's technically not! (And if you go as
     // far to allow everything as specified by the DNS spec...
     // well, that's literally everything, modulo some space limits
     // for the components and the overall name (which, by the way,
     // we are NOT checking!).  So we (arbitrarily) decide this:
     // let's allow underscores wherever we would have allowed
     // hyphens, if they are enabled.  This is a pretty good match
     // for browser behavior, for example, a large number of browsers
     // cannot handle foo_.example.com, but foo_bar.example.com is
     // fairly well supported.
     $underscore = $config->get('Core.AllowHostnameUnderscore') ? '_' : '';
     // The productions describing this are:
     $a = '[a-z]';
     // alpha
     $an = '[a-z0-9]';
     // alphanum
     $and = "[a-z0-9-{$underscore}]";
     // alphanum | "-"
     // domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
     $domainlabel = "{$an}({$and}*{$an})?";
     // toplabel    = alpha | alpha *( alphanum | "-" ) alphanum
     $toplabel = "{$a}({$and}*{$an})?";
     // hostname    = *( domainlabel "." ) toplabel [ "." ]
     if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
         return $string;
     }
     // If we have Net_IDNA2 support, we can support IRIs by
     // punycoding them. (This is the most portable thing to do,
     // since otherwise we have to assume browsers support
     if ($config->get('Core.EnableIDNA')) {
         $idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
         // we need to encode each period separately
         $parts = explode('.', $string);
         try {
             $new_parts = array();
             foreach ($parts as $part) {
                 $encodable = false;
                 for ($i = 0, $c = strlen($part); $i < $c; $i++) {
                     if (ord($part[$i]) > 0x7a) {
                         $encodable = true;
                         break;
                     }
                 }
                 if (!$encodable) {
                     $new_parts[] = $part;
                 } else {
                     $new_parts[] = $idna->encode($part);
                 }
             }
             $string = implode('.', $new_parts);
             if (preg_match("/^({$domainlabel}\\.)*{$toplabel}\\.?\$/i", $string)) {
                 return $string;
             }
         } catch (Exception $e) {
             // XXX error reporting
         }
     }
     return false;
 }
开发者ID:dingdong2310,项目名称:g5_theme,代码行数:95,代码来源:HTMLPurifier.standalone.php


示例18: decodeIDN

 /**
  * Converts given punycode to the IDN.
  *
  * @param string $value punycode to be converted.
  *
  * @return string resulting IDN.
  * @since 1.1.13
  */
 private function decodeIDN($value)
 {
     if (preg_match_all('/^(.*):\\/\\/([^\\/]+)(.*)$/', $value, $matches)) {
         if (function_exists('idn_to_utf8')) {
             $value = $matches[1][0] . '://' . idn_to_utf8($matches[2][0]) . $matches[3][0];
         } else {
             require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Net_IDNA2' . DIRECTORY_SEPARATOR . 'IDNA2.php';
             $idna = new Net_IDNA2();
             $value = $matches[1][0] . '://' . @$idna->decode($matches[2][0]) . $matches[3][0];
         }
     }
     return $value;
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:21,代码来源:UrlValidator.php



注:本文中的Net_IDNA2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Net_IPv4类代码示例发布时间:2022-05-23
下一篇:
PHP Net_DNS_Resolver类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap