Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字符串转换为小代码时出现问题(在PHP中,使用phlyLabs';的小代码字符串转换器)_Php_Utf 8_Punycode - Fatal编程技术网

将字符串转换为小代码时出现问题(在PHP中,使用phlyLabs';的小代码字符串转换器)

将字符串转换为小代码时出现问题(在PHP中,使用phlyLabs';的小代码字符串转换器),php,utf-8,punycode,Php,Utf 8,Punycode,我正在使用下面的代码:并构建了一个类似这样的函数(来自示例): 但是它不能正常工作 我做错了什么$正在传递的inputstring是没有特殊声明的普通字符串。您的字符串已经是UTF-8了吗?看起来是这样。 还是在ISO-8859-5中? 在这两种情况下,您都不能使用PHP函数utf8_encode(),因为它希望您的输入字符串是ISO-88591-1(ISO拉丁语-1,西欧语言)。查看transcode_wrapper.php文件,该文件随类源代码一起提供。这可能会对您有所帮助。您的字符串已经是

我正在使用下面的代码:并构建了一个类似这样的函数(来自示例):

但是它不能正常工作


我做错了什么$正在传递的inputstring是没有特殊声明的普通字符串。

您的字符串已经是UTF-8了吗?看起来是这样。 还是在ISO-8859-5中?
在这两种情况下,您都不能使用PHP函数utf8_encode(),因为它希望您的输入字符串是ISO-88591-1(ISO拉丁语-1,西欧语言)。查看transcode_wrapper.php文件,该文件随类源代码一起提供。这可能会对您有所帮助。

您的字符串已经是UTF-8了吗?看起来是这样。 还是在ISO-8859-5中?
在这两种情况下,您都不能使用PHP函数utf8_encode(),因为它希望您的输入字符串是ISO-88591-1(ISO拉丁语-1,西欧语言)。查看transcode_wrapper.php文件,该文件随类源代码一起提供。这可能会对您有所帮助。

您可能需要

您可能需要

如果可能的话,我只想添加一些类似于使用模块的内容,否则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);}
}

如果可能的话,我只想添加一些类似于使用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);}
}

请尝试此方法转换编码

//$inputstringutf8 = utf8_encode($inputstring);

$inputstringutf8 = mb_convert_encoding($inputstring, 'utf-8', mb_detect_encoding($inputstring));

请尝试此方法转换编码

//$inputstringutf8 = utf8_encode($inputstring);

$inputstringutf8 = mb_convert_encoding($inputstring, 'utf-8', mb_detect_encoding($inputstring));

你好非常感谢。看起来确实如此,它解决了问题!谢谢你!你好非常感谢。看起来确实如此,它解决了问题!谢谢你!