问题描述
我正在使用此处的代码: http://phlymail.com/en/downloads/idna/download/并构建了一个类似的功能(来自示例):
i'm using the code from here: http://phlymail.com/en/downloads/idna/download/ and built a function like this (from the example):
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是没有特殊声明/等的普通字符串.
What am I doing wrong? $inputstring which is being passed is a normal string with no special declarations/etc...
推荐答案
您的字符串已经是UTF-8吗?看起来像它.还是在ISO-8859-5中?在这两种情况下,您都不能使用PHP函数utf8_encode(),因为它期望您的输入字符串为ISO-88591-1(ISO Latin-1,西欧语言).查看随类源提供的文件transcode_wrapper.php.这可能会对您有所帮助.
Is your string already UTF-8? Looks like it.Or is it in ISO-8859-5?In both cases you cannot use the PHP function utf8_encode(), since it expects your input string to be ISO-88591-1 (ISO Latin-1, Western European languages). Look into the file transcode_wrapper.php, which is delivered with the class source. This might help you.
这篇关于将字符串转换为微不足道的代码时出现问题(在PHP中,使用phlyLabs的punycode字符串转换器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!