encode() public méthode

Encode a domain to its Punycode version
public encode ( string $input ) : string
$input string Domain name in Unicode to be encoded
Résultat string Punycode representation in ASCII
Exemple #1
0
function encode_punycode_item($name, $useutf8 = true)
{
    if (substr($name, 0, 4) != "xn--") {
        if (!$useutf8) {
            $name = encode_utf8($name);
        }
        $punycode = new Punycode();
        $name = $punycode->encode($name);
    }
    return $name;
}
Exemple #2
0
function convert_punycode($url, $is_encode = true)
{
    $url_parts = parse_url($url);
    $Punycode = new Punycode();
    if ($is_encode) {
        $host = $Punycode->encode($url_parts['host']);
    } else {
        $host = $Punycode->decode($url_parts['host']);
    }
    $url_parts['host'] = $host;
    return http_build_url($url, $url_parts);
}
Exemple #3
0
 /**
  * Test encoding Punycode
  *
  * @param string $decoded Decoded domain
  * @param string $encoded Encoded domain
  * @dataProvider domainNamesProvider
  */
 public function testEncode($decoded, $encoded)
 {
     $Punycode = new Punycode();
     $result = $Punycode->encode($decoded);
     $this->assertEquals($encoded, $result);
 }
Exemple #4
0
            foreach ($codepoints as $c) {
                if ($c < $n) {
                    ++$delta;
                } else {
                    if ($c == $n) {
                        $q = $delta;
                        $k = 0;
                        while ($k += self::BASE) {
                            $t = $k <= $bias ? self::TMIN : ($k >= $bias + self::TMAX ? self::TMAX : $k - $bias);
                            if ($q < $t) {
                                break;
                            }
                            $output .= self::$ENCODE_TABLE[$t + ($q - $t) % (self::BASE - $t)];
                            $q = (int) (($q - $t) / (self::BASE - $t));
                        }
                        $output .= self::$ENCODE_TABLE[$q];
                        $bias = self::adapt($delta, $h + 1, $h == $b);
                        $delta = 0;
                        ++$h;
                    }
                }
            }
            ++$delta;
            ++$n;
        }
        return $output;
    }
}
$Punycode = new Punycode();
$msg = "UTF-8: " . $Punycode->decode($plugin_text) . "\nPunnycode: " . $Punycode->encode($plugin_text);
$BOT->msg($plugin_sendto, $msg);
Exemple #5
0
/**
 * 保存网站设置选项
 */
function SaveSetting()
{
    global $zbp;
    foreach ($_POST as $key => $value) {
        if (substr($key, 0, 2) !== 'ZC') {
            continue;
        }
        if ($key == 'ZC_PERMANENT_DOMAIN_ENABLE' || $key == 'ZC_COMMENT_TURNOFF' || $key == 'ZC_COMMENT_REVERSE_ORDER' || $key == 'ZC_COMMENT_AUDIT' || $key == 'ZC_DISPLAY_SUBCATEGORYS' || $key == 'ZC_GZIP_ENABLE' || $key == 'ZC_SYNTAXHIGHLIGHTER_ENABLE' || $key == 'ZC_COMMENT_VERIFY_ENABLE' || $key == 'ZC_CLOSE_SITE') {
            $zbp->option[$key] = (bool) $value;
            continue;
        }
        if ($key == 'ZC_RSS2_COUNT' || $key == 'ZC_UPLOAD_FILESIZE' || $key == 'ZC_DISPLAY_COUNT' || $key == 'ZC_SEARCH_COUNT' || $key == 'ZC_PAGEBAR_COUNT' || $key == 'ZC_COMMENTS_DISPLAY_COUNT' || $key == 'ZC_MANAGE_COUNT') {
            $zbp->option[$key] = (int) $value;
            continue;
        }
        if ($key == 'ZC_UPLOAD_FILETYPE') {
            $value = strtolower($value);
            $value = DelNameInString($value, 'php');
            $value = DelNameInString($value, 'asp');
        }
        if ($key == 'ZC_DEBUG_MODE') {
            if ((bool) $value) {
                $zbp->option['ZC_DEBUG_MODE'] = true;
                $zbp->option['ZC_DEBUG_MODE_STRICT'] = true;
                $zbp->option['ZC_DEBUG_LOG_ERROR'] = true;
            } else {
                $zbp->option['ZC_DEBUG_MODE'] = false;
                $zbp->option['ZC_DEBUG_MODE_STRICT'] = false;
                $zbp->option['ZC_DEBUG_LOG_ERROR'] = false;
            }
        }
        $zbp->option[$key] = trim(str_replace(array("\r", "\n"), array("", ""), $value));
    }
    $Punycode = new Punycode();
    $zbp->option['ZC_BLOG_HOST'] = trim($zbp->option['ZC_BLOG_HOST']);
    $zbp->option['ZC_BLOG_HOST'] = trim($zbp->option['ZC_BLOG_HOST'], '/') . '/';
    if ($zbp->option['ZC_BLOG_HOST'] == '/') {
        $zbp->option['ZC_BLOG_HOST'] = $zbp->host;
    }
    $zbp->option['ZC_BLOG_HOST'] = $Punycode->encode($zbp->option['ZC_BLOG_HOST']);
    $lang = (require $zbp->usersdir . 'language/' . $zbp->option['ZC_BLOG_LANGUAGEPACK'] . '.php');
    $zbp->option['ZC_BLOG_LANGUAGE'] = $lang['lang'];
    $zbp->option['ZC_BLOG_PRODUCT'] = 'Z-BlogPHP';
    $zbp->SaveOption();
}
Exemple #6
0
 /**
  * Test encoding Punycode in uppercase
  *
  * @param string $decoded Decoded domain
  * @param string $encoded Encoded domain
  * @dataProvider domainNamesProvider
  */
 public function testEncodeUppercase($decoded, $encoded)
 {
     $Punycode = new Punycode();
     $result = $Punycode->encode(mb_strtoupper($decoded, 'UTF-8'));
     $this->assertEquals($encoded, $result);
 }