本文整理汇总了PHP中Net_IDNA2::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_IDNA2::decode方法的具体用法?PHP Net_IDNA2::decode怎么用?PHP Net_IDNA2::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_IDNA2
的用法示例。
在下文中一共展示了Net_IDNA2::decode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: catch
function idn_to_utf8($domain)
{
static $idn, $loaded;
if (!$loaded) {
$idn = new Net_IDNA2();
$loaded = true;
}
if ($idn && $domain && preg_match('/(^|\\.)xn--/i', $domain)) {
try {
$domain = $idn->decode($domain);
} catch (Exception $e) {
}
}
return $domain;
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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;
}
示例6: decode_idna
/**
* Decodes a String from IDNA format to UTF8
*
* @param $input
* @return string
*/
function decode_idna($input)
{
if (function_exists('idn_to_utf8')) {
// return idn_to_utf8($input, IDNA_USE_STD3_RULES);
return idn_to_utf8($input);
} else {
$IDNA = new Net_IDNA2();
$output = $IDNA->decode($input);
return $output == false ? $input : $output;
}
}
示例7: 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'] . (empty($components['port']) ? '' : ':' . $components['port']);
if (self::isPunycoded($host)) {
try {
$idn = new \Net_IDNA2();
$host = $idn->decode($host);
} catch (\InvalidArgumentException $e) {
}
}
$path = !empty($components['path']) ? $components['path'] : '';
return $host . rtrim($path, '/');
}
return false;
}
示例8: 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;
}