0 レビュー
4 回答
utf 8-文字列をpunyコードに変換する際の問題(PHPでは、phlyLabsのpunycode文字列コンバーターを使用)
ここのコードを使用しています: 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は、特別な宣言などのない通常の文字列です...
わからない
0
レビュー
答え :
解決策:
あなたの文字列はすでにUTF-8ですか?そのように見える。 それともISO-8859-5ですか? どちらの場合も、PHP関数utf8_encode()は、入力文字列がISO-88591-1(ISO Latin-1、西ヨーロッパ言語)であると想定しているため、使用できません。クラスソースとともに提供されるファイルtranscode_wrapper.phpを調べます。これはあなたを助けるかもしれません。
わからない
0
レビュー
答え :
解決策:
可能であれば、モジュールを使用するようなものを追加します。それ以外の場合は、Daveが機能を提案しました:
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);}
}
わからない
0
レビュー
答え :
解決策:
この方法を試してエンコーディングを変換してください
//$inputstringutf8 = utf8_encode($inputstring);
$inputstringutf8 = mb_convert_encoding($inputstring, 'utf-8', mb_detect_encoding($inputstring));
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。