__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
namespace Algo26\IdnaConvert;
use Algo26\IdnaConvert\Exception\InvalidCharacterException;
use Algo26\IdnaConvert\Exception\InvalidIdnVersionException;
use Algo26\IdnaConvert\Punycode\ToPunycode;
use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode;
class ToIdn extends AbstractIdnaConvert implements IdnaConvertInterface
{
/** @var TranscodeUnicode */
private $unicodeTransCoder;
/** @var ToPunycode */
private $punycodeEncoder;
/**
* @throws InvalidIdnVersionException
*/
public function __construct($idnVersion = null)
{
$this->unicodeTransCoder = new TranscodeUnicode();
$this->punycodeEncoder = new ToPunycode($idnVersion);
}
/**
* @param string $host
*
* @return string
* @throws InvalidCharacterException
* @throws Exception\AlreadyPunycodeException
*/
public function convert(string $host): string
{
if (strlen($host) === 0) {
return $host;
}
if (strpos('/', $host) !== false
|| strpos(':', $host) !== false
|| strpos('?', $host) !== false
|| strpos('@', $host) !== false
) {
throw new InvalidCharacterException('Neither email addresses nor URLs are allowed', 205);
}
// These three punctuation characters are treated like the dot
$host = str_replace(['。', '.', '。'], '.', $host);
// Operate per label
$hostLabels = explode('.', $host);
foreach ($hostLabels as $index => $label) {
$asUcs4Array = $this->unicodeTransCoder->convert(
$label,
$this->unicodeTransCoder::FORMAT_UTF8,
$this->unicodeTransCoder::FORMAT_UCS4_ARRAY
);
$encoded = $this->punycodeEncoder->convert($asUcs4Array);
if ($encoded) {
$hostLabels[$index] = $encoded;
}
}
return implode('.', $hostLabels);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| EncodingHelper | Folder | 0775 |
|
|
| Exception | Folder | 0775 |
|
|
| NamePrep | Folder | 0775 |
|
|
| Punycode | Folder | 0775 |
|
|
| TranscodeUnicode | Folder | 0775 |
|
|
| AbstractIdnaConvert.php | File | 1.18 KB | 0664 |
|
| IdnaConvertInterface.php | File | 249 B | 0664 |
|
| ToIdn.php | File | 1.94 KB | 0664 |
|
| ToUnicode.php | File | 969 B | 0664 |
|