当前位置: 首页>>代码示例>>PHP>>正文


PHP Net_IDNA2::encode方法代码示例

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


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

示例1: normalizeDomain

 /**
  * Normalizes domain name and punycode's it
  * @param  string $url URL
  * @return mixed  string with normalized domain on success, boolean false otherwise
  */
 public static function normalizeDomain($url)
 {
     $url = self::fix($url);
     if ($url) {
         $domain = parse_url($url, PHP_URL_HOST);
         if (strpos($domain, self::PUNYCODE_PREFIX) !== 0) {
             $idn = new \Net_IDNA2();
             $domain = $idn->encode($domain);
         }
         return $domain;
     }
     return false;
 }
开发者ID:OneataBogdan,项目名称:lead_coriolan,代码行数:18,代码来源:Url.php

示例2: 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

示例3: catch

 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

示例4: 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

示例5: array

        $request_params = array('ListType' => "COMPLETED", 'PageSize' => 100, 'SortBy' => "DOMAINNAME");
        if (!empty($params['PromotionCode'])) {
            $request_params['PromotionCode'] = $params['PromotionCode'];
        }
        $api = new NamecheapRegistrarApi($username, $password, $testmode);
        $response = $api->request("namecheap.domains.transfer.getList", $request_params);
        $result = $api->parseResponse($response);
        $transfers = namecheap_parseResult($result['TransferGetListResult']['Transfer']);
    } catch (Exception $e) {
        $report .= $e->getMessage() . "\n";
    }
    if (!$transfers) {
        $report .= "No registrar completed transfers found\n";
    } else {
        while (($row = mysql_fetch_assoc($dbresult)) !== false) {
            $row['domain'] = $idna2->encode($row['domain']);
            $report .= "Domain " . $row['domain'];
            if (isset($transfers[$row['domain']]) && "COMPLETED" == $transfers[$row['domain']]['Status']) {
                $t = $transfers[$row['domain']];
                $update = array('status' => "Active");
                update_query("tbldomains", $update, array('id' => $row['id']));
                $report .= " transfer status updated\n";
            } else {
                $report .= " skipped\n";
            }
        }
    }
}
/**
 * Active domains expiration and next due date dates synchronization
 */
开发者ID:billyprice1,项目名称:whmcs,代码行数:31,代码来源:namecheapsync.php

示例6: 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

示例7: 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

示例8: encodePunycode

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

示例9: 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

示例10: encode_host

/**
 * Encodes to punycode
 * @param string $host ONLY the host name, e.g. "испытание.рф"
 * @return string
 */
function encode_host($host)
{
    if (!preg_match("/[^\\w\\-\\.]/", $host)) {
        return $host;
    }
    require_once 'Net/IDNA2.php';
    // netcat/require/lib
    $encoder = new Net_IDNA2();
    try {
        $host = $encoder->encode(strtolower($host));
    } catch (Net_IDNA2_Exception $e) {
        trigger_error("Cannot convert host name '{$host}' to punycode: {$e->getMessage()}", E_USER_WARNING);
        return $host;
    }
    return $host;
}
开发者ID:Blu2z,项目名称:implsk,代码行数:21,代码来源:s_common.inc.php

示例11: __construct

 public function __construct($sld, $tld)
 {
     $this->_sld = $sld;
     $this->_tld = $tld;
     if (in_array($tld, self::$_tldList)) {
         $this->_tldInList = true;
         $idna2 = new Net_IDNA2();
         try {
             $this->_encodedSld = $idna2->encode($sld);
         } catch (Exception $e) {
             $this->_encodedSld = $sld;
         }
         if ($sld != $this->_encodedSld) {
             $this->_sldWasEncoded = true;
         }
     } else {
         $this->_encodedSld = $sld;
     }
     return $this;
 }
开发者ID:MarcelaGotta,项目名称:Webty,代码行数:20,代码来源:namecheapapi.php

示例12: 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

示例13: _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

示例14: 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


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