0

私はここからコードを使用しています: http://phlymail.com/en/downloads/idna/download/そして、このような関数を構築しました (例から):

function convert_to_punycode($inputstring)
{
    $IDN = new idna_convert();
    // The input string, if input is not UTF-8 or UCS-4, it must be converted before
    $inputstringutf8 = utf8_encode($inputstring);
    // Encode it to its punycode presentation
    $outputstringpunycode = $IDN->encode($inputstringutf8);
    return $outputstringpunycode;
}

ただし、正しく動作しません。

For the input: Россию
It gives: РоÑÑиÑ
Whereas it should give: xn--h1alffa3f

私は何を間違っていますか?渡される $inputstring は、特別な宣言などのない通常の文字列です...

4

4 に答える 4

3

文字列は既に UTF-8 ですか? そのように見える。それともISO-8859-5ですか?どちらの場合も、入力文字列が ISO-88591-1 (ISO Latin-1、西ヨーロッパ言語) であると想定されるため、PHP 関数 utf8_encode() を使用することはできません。クラスソースに同梱されているファイル transcode_wrapper.php を調べます。これはあなたを助けるかもしれません。

于 2010-06-28T16:28:49.997 に答える
0

PHPIDNA拡張機能が必要になる場合があります

于 2010-06-28T16:32:59.653 に答える
0

可能であればモジュールを使用するようなものを追加するだけです。それ以外の場合は、デイブが機能を提案しました:

if(!function_exists('idn_to_ascii') and !function_exists('idn_to_utf8'))
{   define('IDN_FALLBACK_VERSION',2008);
    require_once('idna_convert.class.php');
    function idn_to_ascii($string)
    {   $IDN = new idna_convert(array('idn_version'=>IDN_FALLBACK_VERSION));
        return $IDN->encode($string);
    }
    function idn_to_utf8($string)
    {   $IDN = new idna_convert(array('idn_version'=>IDN_FALLBACK_VERSION));
        return $IDN->decode($string);
    }
    function idn_to_unicode($string){return idn_to_utf8($string);}
}
于 2015-05-10T08:02:06.090 に答える