本文整理汇总了PHP中idn_to_utf8函数的典型用法代码示例。如果您正苦于以下问题:PHP idn_to_utf8函数的具体用法?PHP idn_to_utf8怎么用?PHP idn_to_utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了idn_to_utf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decode
/**
* Decode a Punycode domain name to its Unicode counterpart
*
* @param string $input Domain name in Punycode
*
* @return string Unicode domain name
*/
public function decode($input)
{
if ($this->idnSupport === true) {
return idn_to_utf8($input);
}
return self::$punycode->decode($input);
}
示例2: getIdn
/**
* Get internationalized domain name
*
* @return null|false|string
*/
public function getIdn()
{
if (empty($this->domain)) {
return null;
}
return @idn_to_utf8($this->domain);
}
示例3: 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;
}
示例4: filter
public function filter(string $host) : string
{
$host = $this->validateHost($host);
if ($this->isIdn) {
$host = idn_to_utf8($host);
}
return $this->lower($host);
}
示例5: create_identity
public function create_identity($p)
{
$rcmail = rcmail::get_instance();
// prefs are set in create_user()
if ($this->prefs) {
if ($this->prefs['full_name']) {
$p['record']['name'] = $this->prefs['full_name'];
}
if (($this->identities_level == 0 || $this->identities_level == 2) && $this->prefs['email_address']) {
$p['record']['email'] = $this->prefs['email_address'];
}
if ($this->prefs['___signature___']) {
$p['record']['signature'] = $this->prefs['___signature___'];
}
if ($this->prefs['reply_to']) {
$p['record']['reply-to'] = $this->prefs['reply_to'];
}
if (($this->identities_level == 0 || $this->identities_level == 1) && isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
for ($i = 1; $i < $this->prefs['identities']; $i++) {
unset($ident_data);
$ident_data = array('name' => '', 'email' => '');
// required data
if ($this->prefs['full_name' . $i]) {
$ident_data['name'] = $this->prefs['full_name' . $i];
}
if ($this->identities_level == 0 && $this->prefs['email_address' . $i]) {
$ident_data['email'] = $this->prefs['email_address' . $i];
} else {
$ident_data['email'] = $p['record']['email'];
}
if ($this->prefs['reply_to' . $i]) {
$ident_data['reply-to'] = $this->prefs['reply_to' . $i];
}
if ($this->prefs['___sig' . $i . '___']) {
$ident_data['signature'] = $this->prefs['___sig' . $i . '___'];
}
// insert identity
$identid = $rcmail->user->insert_identity($ident_data);
}
}
// copy address book
$contacts = $rcmail->get_address_book(null, true);
if ($contacts && count($this->abook)) {
foreach ($this->abook as $rec) {
// #1487096 handle multi-address and/or too long items
$rec['email'] = array_shift(explode(';', $rec['email']));
if (check_email(idn_to_ascii($rec['email']))) {
$rec['email'] = idn_to_utf8($rec['email']);
$contacts->insert($rec, true);
}
}
}
// mark identity as complete for following hooks
$p['complete'] = true;
}
return $p;
}
示例6: findBy
/**
* @param array|null $options
* @return Domain[]
*/
public function findBy(array $options = null)
{
$domainObjects = [];
$domainsList = $this->api->getList($options);
foreach ($domainsList as $domainName) {
$domain = idn_to_utf8($domainName->getFqdn());
$domainObjects[] = $this->factory->build($domain);
}
return $domainObjects;
}
示例7: checkDomain
/**
* Check email's domain
*
* @param $value
*
* @return bool
*/
public static function checkDomain($value)
{
static $regexData = ['pattern' => '/^(?:[0-9a-zA-Z](?:[\\-\\+\\_]*[0-9a-zA-Z])*\\.)+[0-9a-zA-Z](?:[\\-\\+\\_]*[0-9a-zA-Z])*$/u'];
$explodedEmail = explode('@', $value);
if (!isset($explodedEmail[1])) {
return false;
}
$preparedDomain = idn_to_utf8($explodedEmail[1]);
return stringValidator::byRegex($preparedDomain, $regexData);
}
示例8: convertIdnToUtf8Format
/**
* Convert idn to utf8 format
*
* @param string $name
*
* @return string
*/
public static function convertIdnToUtf8Format($name)
{
if (empty($name)) {
return;
}
if (!function_exists('idn_to_utf8')) {
\DBG::msg('Idn is not supported in this system.');
} else {
$name = idn_to_utf8($name);
}
return $name;
}
示例9: __set
/**
*/
public function __set($name, $value)
{
switch ($name) {
case 'host':
$value = ltrim($value, '@');
$this->_host = function_exists('idn_to_utf8') ? strtolower(idn_to_utf8($value)) : strtolower($value);
break;
case 'personal':
$this->_personal = strlen($value) ? Horde_Mime::decode($value) : null;
break;
}
}
示例10: test_invalidTld
public function test_invalidTld()
{
$tlds = [strval(bin2hex(openssl_random_pseudo_bytes(64))), '-tld-cannot-start-from-hypen', 'ąęśćżźł-there-is-no-such-idn', 'xn--fd67as67fdsa', '!@#-inavlid-chars-in-tld', 'no spaces in tld allowed', 'no--double--hypens--allowed'];
if (count($tlds) === 0) {
$this->markTestSkipped("Couldn't get TLD list");
}
foreach ($tlds as $key => $tld) {
if (strpos(mb_strtolower($tld), 'xn--') !== 0) {
$tld = mb_strtolower($tld);
}
$this->assertFalse($this->isValid('test@example.' . idn_to_utf8($tld)));
}
}
示例11: listIPDomains
/**
* Generate List of Domains assigned to IPs
*
* @param iMSCP_pTemplate $tpl Template engine
* @return void
*/
function listIPDomains($tpl)
{
$resellerId = $_SESSION['user_id'];
$stmt = exec_query('SELECT reseller_ips FROM reseller_props WHERE reseller_id = ?', $resellerId);
$data = $stmt->fetchRow();
$resellerIps = explode(';', substr($data['reseller_ips'], 0, -1));
$stmt = execute_query('SELECT ip_id, ip_number FROM server_ips WHERE ip_id IN (' . implode(',', $resellerIps) . ')');
while ($ip = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
$stmt2 = exec_query('
SELECT
domain_name
FROM
domain
INNER JOIN
admin ON(admin_id = domain_admin_id)
WHERE
domain_ip_id = :ip_id
AND
created_by = :reseller_id
UNION
SELECT
alias_name AS domain_name
FROM
domain_aliasses
INNER JOIN
domain USING(domain_id)
INNER JOIN
admin ON(admin_id = domain_admin_id)
WHERE
alias_ip_id = :ip_id
AND
created_by = :reseller_id
', array('ip_id' => $ip['ip_id'], 'reseller_id' => $resellerId));
$domainsCount = $stmt2->rowCount();
$tpl->assign(array('IP' => tohtml($ip['ip_number']), 'RECORD_COUNT' => tr('Total Domains') . ': ' . $domainsCount));
if ($domainsCount) {
while ($data = $stmt2->fetchRow(PDO::FETCH_ASSOC)) {
$tpl->assign('DOMAIN_NAME', tohtml(idn_to_utf8($data['domain_name'])));
$tpl->parse('DOMAIN_ROW', '.domain_row');
}
} else {
$tpl->assign('DOMAIN_NAME', tr('No used yet'));
$tpl->parse('DOMAIN_ROW', 'domain_row');
}
$tpl->parse('IP_ROW', '.ip_row');
$tpl->assign('DOMAIN_ROW', '');
}
}
示例12: validateStringHost
/**
* Validate a string only host
*
* @param string $str
*
* @return array
*/
protected function validateStringHost($str)
{
if (empty($str)) {
return [];
}
$host = $this->lower($this->setIsAbsolute($str));
$raw_labels = explode('.', $host);
$labels = array_map(function ($value) {
return idn_to_ascii($value);
}, $raw_labels);
$this->assertValidHost($labels);
$this->isIdn = $raw_labels !== $labels;
return array_reverse(array_map(function ($label) {
return idn_to_utf8($label);
}, $labels));
}
示例13: setPattern
public function setPattern($arr, $page)
{
list(, $alias, $toname, $host) = $this->splice($arr);
$name = $orginalname = $toname . $host;
if (extension_loaded('intl')) {
// 国際化ドメイン対応
if (preg_match('/[^A-Za-z0-9.-]/', $host)) {
$name = $toname . idn_to_ascii($host);
} else {
if (!$alias && strtolower(substr($host, 0, 4)) === 'xn--') {
$orginalname = $toname . idn_to_utf8($host);
}
}
}
return parent::setParam($page, $name, '', 'mailto', $alias === '' ? $orginalname : $alias);
}
示例14: convert_idn_domain
/**
* @return string
*/
function convert_idn_domain($domain)
{
// Get domain length
$domain_length = strlen($domain);
// Perform two idn operations, convert to ascii and convert to utf8
$idn_ascii_domain = idn_to_ascii($domain);
// IDN utf8 domain detected, return converted domain.
if ($domain_length != strlen($idn_ascii_domain)) {
return $idn_ascii_domain;
}
$idn_utf8_domain = idn_to_utf8($domain);
// IDN ascii domain detected, return converted domain.
if ($domain_length != strlen($idn_utf8_domain)) {
return $idn_utf8_domain;
}
return $domain;
}
示例15: init
function init()
{
if (!empty(App::$primary->config['site']['domain'])) {
$domain = App::$primary->config['site']['domain'];
} else {
$domain = implode('.', array_slice(explode('.', idn_to_utf8(INJI_DOMAIN_NAME)), -2));
}
$alias = str_replace($domain, '', idn_to_utf8(INJI_DOMAIN_NAME));
$city = null;
if ($alias) {
$alias = str_replace('.', '', $alias);
$city = Geography\City::get($alias, 'alias');
}
if (!$city) {
$city = Geography\City::get(1, 'default');
}
Geography\City::$cur = $city;
}