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


PHP idn_to_ascii函数代码示例

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


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

示例1: encode

 /**
  * Encode a domain to its Punycode version
  *
  * @param string $input Domain name in Unicode to be encoded
  *
  * @return string Punycode representation in ASCII
  */
 public function encode($input)
 {
     if ($this->idnSupport === true) {
         return idn_to_ascii($input);
     }
     return self::$punycode->encode($input);
 }
开发者ID:voku,项目名称:php-domain-parser,代码行数:14,代码来源:PunycodeWrapper.php

示例2: idnToAscii

 /**
  * Safely convert UTF-8 encoded domain name to ASCII
  * @param string $domainName  the UTF-8 encoded email
  * @return string
  */
 protected function idnToAscii($domainName)
 {
     if (extension_loaded('intl')) {
         return idn_to_ascii($domainName) ?: $domainName;
     }
     return $domainName;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:12,代码来源:AbstractAddressList.php

示例3: validate

 /**
  * @param Field $field
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     $emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL);
     if ($emailValid === false) {
         return false;
     }
     if ($this->checkMx === false) {
         return true;
     }
     $domain = substr($fieldValue, strrpos($fieldValue, '@') + 1);
     $mxRecords = array();
     if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) {
         return true;
     }
     // Port 25 fallback check if there's no MX record
     $aRecords = dns_get_record($domain, DNS_A);
     if (count($aRecords) <= 0) {
         return false;
     }
     $connection = @fsockopen($aRecords[0]['ip'], 25);
     if (is_resource($connection) === true) {
         fclose($connection);
         return true;
     }
     return false;
 }
开发者ID:TiMESPLiNTER,项目名称:formHandler,代码行数:34,代码来源:ValidEmailAddressRule.php

示例4: santise

 private function santise()
 {
     foreach ($this->domains as $key => $domain) {
         // Add IND support
         $idnDomain = idn_to_ascii($domain);
         if ($idnDomain === false) {
             continue;
         }
         // Validates domain as URL (according to » @link http://www.faqs.org/rfcs/rfc2396)
         if (!filter_var('http://' . idn_to_ascii($idnDomain) . '/', FILTER_VALIDATE_URL)) {
             continue;
         }
         // Replace *.example.com with just example.com
         if (strpos($domain, '*.') === 0) {
             $domain = substr($domain, 2);
         }
         // Doesn't handle wild cards yet.
         if (strpos($domain, '*') !== false) {
             continue;
         }
         // Minimum Length
         // x.yy is sortest domain possible.
         if (empty($domain) || mb_strlen($domain) < 4) {
             continue;
         }
         // Trim and lowercase
         $this->domainsProcessed[] = trim(strtolower($domain));
     }
     $this->domainsProcessedCount = count($this->domainsProcessed);
 }
开发者ID:nojacko,项目名称:email-data-disposable,代码行数:30,代码来源:Domains.php

示例5: isEmail

 /**
  * Valid Email
  *
  * @param   string
  * @return  bool
  */
 public static function isEmail($str)
 {
     if (function_exists('idn_to_ascii') && ($atpos = strpos($str, '@'))) {
         $str = substr($str, 0, ++$atpos) . idn_to_ascii(substr($str, $atpos));
     }
     return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
 }
开发者ID:dreeye,项目名称:helper,代码行数:13,代码来源:Validate_helper.php

示例6: CreatePDNSPass

 /**
  * @return mixed
  */
 public static function CreatePDNSPass()
 {
     System_Daemon::debug('Starting "DaemonConfigDNS::createPDNSPass" subprocess.');
     $xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/tpl/EasySCP_Config_DNS.xml');
     System_Daemon::debug('Building the new pdns config file');
     $xml->{'PDNS_USER'} = 'powerdns';
     $xml->{'PDNS_PASS'} = DB::encrypt_data(DaemonCommon::generatePassword(18));
     $xml->{'HOSTNAME'} = idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'});
     $handle = fopen(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', "wb");
     fwrite($handle, $xml->asXML());
     fclose($handle);
     DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640);
     // Create/Update Powerdns control user account if needed
     System_Daemon::debug('Adding the PowerDNS control user');
     $sql_param = array(':PDNS_USER' => $xml->{'PDNS_USER'}, ':PDNS_PASS' => DB::decrypt_data($xml->{'PDNS_PASS'}), ':HOSTNAME' => $xml->{'HOSTNAME'});
     $sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :PDNS_USER@:HOSTNAME IDENTIFIED BY :PDNS_PASS;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
     DB::prepare($sql_query);
     DB::execute($sql_param)->closeCursor();
     $sql_param = array(':DATABASE_USER' => DaemonConfig::$cfg->DATABASE_USER, ':DATABASE_HOST' => idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'}));
     $sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :DATABASE_USER@:DATABASE_HOST;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
     DB::prepare($sql_query);
     DB::execute($sql_param)->closeCursor();
     System_Daemon::debug('Finished "DaemonConfigDNS::createPDNSPass" subprocess.');
     return true;
 }
开发者ID:gOOvER,项目名称:EasySCP,代码行数:28,代码来源:DaemonConfigDNS.php

示例7: validate

 /**
  * Validates an email address
  *
  * @param     string    $email          Email address
  * @param     boolean   $checkDomain    True if dns check should be performed
  * @access    public
  * @return    boolean   true if email is valid
  */
 function validate($email, $checkDomain = false)
 {
     if (function_exists('idn_to_ascii')) {
         if ($parts = explode('@', $email)) {
             if (sizeof($parts) == 2) {
                 foreach ($parts as &$part) {
                     $part = idn_to_ascii($part);
                 }
                 $email = implode('@', $parts);
             }
         }
     }
     // Fix for bug #10799: add 'D' modifier to regex
     if (preg_match($this->regex . 'D', $email)) {
         if ($checkDomain && function_exists('checkdnsrr')) {
             $tokens = explode('@', $email);
             if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
                 return true;
             }
             return false;
         }
         return true;
     }
     return false;
 }
开发者ID:mollux,项目名称:civicrm-packages,代码行数:33,代码来源:Email.php

示例8: encodeHostName

 public static function encodeHostName($hostname)
 {
     if (!self::is_valid_utf8($hostname)) {
         return $hostname;
         //invalid
     }
     if (function_exists('idn_to_ascii') && 0) {
         return idn_to_ascii($hostname);
         //php 5.3+
     }
     $old_encoding = mb_internal_encoding();
     mb_internal_encoding("UTF-8");
     $pieces = explode(".", self::mb_strtolower($hostname));
     $punycode_pieces = array();
     foreach ($pieces as $piece) {
         if (preg_match("/[\\x{80}-\\x{FFFF}]/u", $piece)) {
             $punycode_pieces[] = "xn--" . self::encode($piece);
         } else {
             if (preg_match('/^[a-z\\d][a-z\\d-]{0,62}$/i', $piece) && !preg_match('/-$/', $piece)) {
                 $punycode_pieces[] = $piece;
             } else {
                 mb_internal_encoding($old_encoding);
                 return $hostname;
                 //invalid domain
             }
         }
     }
     mb_internal_encoding($old_encoding);
     return implode(".", $punycode_pieces);
 }
开发者ID:bitbybit,项目名称:avdetect,代码行数:30,代码来源:Punycode.php

示例9: validateValue

 /**
  * @inheritdoc
  */
 protected function validateValue($value)
 {
     if (!is_string($value)) {
         $valid = false;
     } elseif (!preg_match('/^(?P<name>(?:"?([^"]*)"?\\s)?)(?:\\s+)?(?:(?P<open><?)((?P<local>.+)@(?P<domain>[^>]+))(?P<close>>?))$/i', $value, $matches)) {
         $valid = false;
     } else {
         if ($this->enableIDN) {
             $matches['local'] = idn_to_ascii($matches['local']);
             $matches['domain'] = idn_to_ascii($matches['domain']);
             $value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
         }
         if (strlen($matches['local']) > 64) {
             // The maximum total length of a user name or other local-part is 64 octets. RFC 5322 section 4.5.3.1.1
             // http://tools.ietf.org/html/rfc5321#section-4.5.3.1.1
             $valid = false;
         } elseif (strlen($matches['local'] . '@' . $matches['domain']) > 254) {
             // There is a restriction in RFC 2821 on the length of an address in MAIL and RCPT commands
             // of 254 characters. Since addresses that do not fit in those fields are not normally useful, the
             // upper limit on address lengths should normally be considered to be 254.
             //
             // Dominic Sayers, RFC 3696 erratum 1690
             // http://www.rfc-editor.org/errata_search.php?eid=1690
             $valid = false;
         } else {
             $valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value);
             if ($valid && $this->checkDNS) {
                 $valid = checkdnsrr($matches['domain'], 'MX') || checkdnsrr($matches['domain'], 'A');
             }
         }
     }
     return $valid ? null : [$this->message, []];
 }
开发者ID:arogachev,项目名称:yii2,代码行数:36,代码来源:EmailValidator.php

示例10: isDomainAvailable

 /**
  * Is domain available
  *
  * @param string $domain
  * @return bool
  */
 public function isDomainAvailable($domain, $values = null)
 {
     $domain = @idn_to_ascii($domain);
     if (empty($domain)) {
         return false;
     }
     $config = $this->getServiceLocator()->get('Config')['db'];
     if (!empty($config['defaultDomain']) && $domain == $config['defaultDomain']) {
         return false;
     }
     $parts = explode('.', $domain);
     if (count($parts) < 2) {
         return false;
     }
     if (is_object($values)) {
         $values = (array) $values;
     }
     if (!empty($values['id'])) {
         $excludeId = (int) $values['id'];
     } else {
         $excludeId = null;
     }
     $mapper = $this->getMapper();
     $domain = array_pop($parts);
     do {
         $domain = array_pop($parts) . '.' . $domain;
         if ($mapper->isDomainExists($domain, $excludeId)) {
             return false;
         }
     } while (!empty($parts));
     return true;
 }
开发者ID:gridguyz,项目名称:multisite,代码行数:38,代码来源:Rpc.php

示例11: verifyDomainName

 /**
  * Convert IDN names and verify the validity and specification constraints
  * @param string $domainName Domain name
  * @return string
  */
 private function verifyDomainName($domainName)
 {
     Log::debug('Verify domain: ' . $domainName);
     // Since PHP does not support IDN domain names, convert to ASCII by default
     $domainName = strtolower(idn_to_ascii(trim($domainName)));
     // Validate domain name length, max length 253
     if (strlen($domainName) > 253) {
         Log::error('Domain name exceedes the max length of 253 characters: ' . $domainName);
         return false;
     }
     // Make sure there is at least one "dot"
     if (strpos($domainName, '.') === false) {
         Log::error('Domain name is missing a dot character: ' . $domainName);
         return false;
     }
     // Explode "dot" separated parts
     $parts = explode('.', $domainName);
     // Validate parts
     foreach ($parts as $p) {
         // Max length 63 characters
         if (strlen($p) > 63) {
             Log::error('A domain name part exceedes the mas length of 63 characters: ' . $p);
             return false;
         }
         // Validate characters
         if (preg_match('/^[-a-z0-9]+$/i', $p) !== 1) {
             Log::error('Invalid characters in the domain name part: ' . $p);
             return false;
         }
     }
     return $domainName;
 }
开发者ID:noumenia,项目名称:aetolos,代码行数:37,代码来源:domainhelper.inc.php

示例12: test_compose_withPunycodeHost_returnsValidURL

 public function test_compose_withPunycodeHost_returnsValidURL()
 {
     $punycode = 'http://' . idn_to_ascii('piña.com');
     $expectedComposedUrl = 'http://xn--pia-8ma.com';
     $url = new UrlComposer($punycode);
     $this->assertEquals($expectedComposedUrl, $url->compose());
 }
开发者ID:retrinko,项目名称:url-composer,代码行数:7,代码来源:UrlComposerTest.php

示例13: isValidDomain

 /**
  * Return true if a domain is a valid domain.
  * @link https://url.spec.whatwg.org/#valid-domain URL Standard
  * @param string $domain A UTF-8 string.
  * @return boolean
  */
 public static function isValidDomain($domain)
 {
     $valid = mb_strlen($domain, 'UTF-8') <= self::PHP_IDN_HANDLEABLE_LENGTH;
     if ($valid) {
         $result = idn_to_ascii($domain, IDNA_USE_STD3_RULES | IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
         if (!is_string($result)) {
             $valid = false;
         }
     }
     if ($valid) {
         $domainNameLength = strlen($result);
         if ($domainNameLength < 1 || $domainNameLength > 253) {
             $valid = false;
         }
     }
     if ($valid) {
         foreach (explode('.', $result) as $label) {
             $labelLength = strlen($label);
             if ($labelLength < 1 || $labelLength > 63) {
                 $valid = false;
                 break;
             }
         }
     }
     if ($valid) {
         $result = idn_to_utf8($result, IDNA_USE_STD3_RULES, INTL_IDNA_VARIANT_UTS46, $idna_info);
         if ($idna_info['errors'] !== 0) {
             $valid = false;
         }
     }
     return $valid;
 }
开发者ID:esperecyan,项目名称:url,代码行数:38,代码来源:HostProcessing.php

示例14: setDomain

 /**
  * Set domain
  *
  * @param string $domain
  * @return \MultisitePlatform\Model\Domain\Structure
  */
 public function setDomain($domain)
 {
     $domain = @idn_to_ascii($domain);
     if (!empty($domain)) {
         $this->domain = $domain;
     }
     return $this;
 }
开发者ID:gridguyz,项目名称:multisite,代码行数:14,代码来源:Structure.php

示例15: valid_email

 function valid_email($address)
 {
     $patternselect = 'auto';
     //
     // Added by Ivan Tcholakov, 17-OCT-2015.
     if (function_exists('idn_to_ascii') && ($atpos = strpos($address, '@'))) {
         $address = substr($address, 0, ++$atpos) . idn_to_ascii(substr($address, $atpos));
     }
     //
     if (!$patternselect or $patternselect == 'auto') {
         //Check this constant first so it works when extension_loaded() is disabled by safe mode
         //Constant was added in PHP 5.2.4
         if (defined('PCRE_VERSION')) {
             //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
             if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
                 $patternselect = 'pcre8';
             } else {
                 $patternselect = 'pcre';
             }
         } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
             //Fall back to older PCRE
             $patternselect = 'pcre';
         } else {
             //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
             if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
                 $patternselect = 'php';
             } else {
                 $patternselect = 'noregex';
             }
         }
     }
     switch ($patternselect) {
         case 'pcre8':
             /**
              * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
              * @link http://squiloople.com/2009/12/20/email-address-validation/
              * @copyright 2009-2010 Michael Rushton
              * Feel free to use and redistribute this code. But please keep this copyright notice.
              */
             return (bool) preg_match('/^(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){65,}@)' . '((?>(?>(?>((?>(?>(?>\\x0D\\x0A)?[\\t ])+|(?>[\\t ]*\\x0D\\x0A)?[\\t ]+)?)(\\((?>(?2)' . '(?>[\\x01-\\x08\\x0B\\x0C\\x0E-\'*-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]|(?3)))*(?2)\\)))+(?2))|(?2))?)' . '([!#-\'*+\\/-9=?^-~-]+|"(?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]))*' . '(?2)")(?>(?1)\\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' . '(?>(?1)\\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' . '|(?!(?:.*[a-f0-9][:\\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' . '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\\.(?9)){3}))\\])(?1)$/isD', $address);
         case 'pcre':
             //An older regex that doesn't need a recent PCRE
             return (bool) preg_match('/^(?!(?>"?(?>\\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\\[ -~]|[^"])"?){65,}@)(?>' . '[!#-\'*+\\/-9=?^-~-]+|"(?>(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\xFF]))*")' . '(?>\\.(?>[!#-\'*+\\/-9=?^-~-]+|"(?>(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\xFF]))*"))*' . '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\\.(?![a-z0-9-]{64,})' . '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' . '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' . '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' . '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' . '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\\])$/isD', $address);
         case 'html5':
             /**
              * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
              * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
              */
             return (bool) preg_match('/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' . '[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
         case 'noregex':
             //No PCRE! Do something _very_ approximate!
             //Check the address is 3 chars or longer and contains an @ that's not the first or last char
             return strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1;
         case 'php':
         default:
             return (bool) filter_var($address, FILTER_VALIDATE_EMAIL);
     }
 }
开发者ID:aslijiasheng,项目名称:ciFramework,代码行数:58,代码来源:MY_email_helper.php


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