Source for file punycode.php
Documentation is available at punycode.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Joomla Platform String Punycode Class
* Class for handling UTF-8 URLs
* Wraps the Punycode library
* All functions assume the validity of utf-8 URLs.
* @package Joomla.Platform
* Transforms a UTF-8 string to a Punycode string
* @param string $utfString The UTF-8 string to transform
* @return string The punycode string
return $idn->encode($utfString);
* Transforms a Punycode string to a UTF-8 string
* @param string $punycodeString The Punycode string to transform
* @return string The UF-8 URL
return $idn->decode($punycodeString);
* Transforms a UTF-8 URL to a Punycode URL
* @param string $uri The UTF-8 URL to transform
* @return string The punycode URL
if (!isset
($parsed['host']) ||
$parsed['host'] ==
'')
// If there is no host we do not need to convert it.
$hostExploded =
explode('.', $host);
foreach ($hostExploded as $hostex)
$hostex =
static::toPunycode($hostex);
$newhost .=
$hostex .
'.';
$newhost =
substr($newhost, 0, -
1);
if (!empty($parsed['scheme']))
// Assume :// is required although it is not always.
$newuri .=
$parsed['scheme'] .
'://';
if (!empty($parsed['port']))
$newuri .=
':' .
$parsed['port'];
if (!empty($parsed['path']))
$newuri .=
$parsed['path'];
if (!empty($parsed['query']))
$newuri .=
'?' .
$parsed['query'];
* Transforms a Punycode URL to a UTF-8 URL
* @param string $uri The Punycode URL to transform
* @return string The UTF-8 URL
if (!isset
($parsed['host']) ||
$parsed['host'] ==
'')
// If there is no host we do not need to convert it.
$hostExploded =
explode('.', $host);
foreach ($hostExploded as $hostex)
$hostex =
self::fromPunycode($hostex);
$newhost .=
$hostex .
'.';
$newhost =
substr($newhost, 0, -
1);
if (!empty($parsed['scheme']))
// Assume :// is required although it is not always.
$newuri .=
$parsed['scheme'] .
'://';
if (!empty($parsed['port']))
$newuri .=
':' .
$parsed['port'];
if (!empty($parsed['path']))
$newuri .=
$parsed['path'];
if (!empty($parsed['query']))
$newuri .=
'?' .
$parsed['query'];
* Transforms a UTF-8 e-mail to a Punycode e-mail
* This assumes a valid email address
* @param string $email The UTF-8 e-mail to transform
* @return string The punycode e-mail
$explodedAddress =
explode('@', $email);
// Not addressing UTF-8 user names
$newEmail =
$explodedAddress[0];
if (!empty($explodedAddress[1]))
$domainExploded =
explode('.', $explodedAddress[1]);
foreach ($domainExploded as $domainex)
$domainex =
static::toPunycode($domainex);
$newdomain .=
$domainex .
'.';
$newdomain =
substr($newdomain, 0, -
1);
$newEmail =
$newEmail .
'@' .
$newdomain;
* Transforms a Punycode e-mail to a UTF-8 e-mail
* This assumes a valid email address
* @param string $email The punycode e-mail to transform
* @return string The punycode e-mail
$explodedAddress =
explode('@', $email);
// Not addressing UTF-8 user names
$newEmail =
$explodedAddress[0];
if (!empty($explodedAddress[1]))
$domainExploded =
explode('.', $explodedAddress[1]);
foreach ($domainExploded as $domainex)
$domainex =
static::fromPunycode($domainex);
$newdomain .=
$domainex .
'.';
$newdomain =
substr($newdomain, 0, -
1);
$newEmail =
$newEmail .
'@' .
$newdomain;
Documentation generated on Tue, 19 Nov 2013 15:11:25 +0100 by phpDocumentor 1.4.3