Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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 使用特定字符集进行URL编码_Php_Html_Encoding_Character Encoding_Urlencode - Fatal编程技术网

Php 使用特定字符集进行URL编码

Php 使用特定字符集进行URL编码,php,html,encoding,character-encoding,urlencode,Php,Html,Encoding,Character Encoding,Urlencode,当我尝试使用GB2312编码的“”链接时,它返回我想要的%D4%B2%CD%A8%CB%D9%B5%DD。但是当我在php中使用 $urlencoded = urlencode('圆通速递'); 它回来了 %E5%9C%86%E9%80%9A%E9%80%9F%E9%80%92 结果不是我想要的。如何在特定的字符集中对URL进行编码?您应该首先尝试转换字符串的编码。大概是这样的: $urlencoded = urlencode(mb_convert_encoding('圆通速递','GB23

当我尝试使用GB2312编码的“”链接时,它返回我想要的
%D4%B2%CD%A8%CB%D9%B5%DD
。但是当我在php中使用

$urlencoded = urlencode('圆通速递');
它回来了

%E5%9C%86%E9%80%9A%E9%80%9F%E9%80%92

结果不是我想要的。如何在特定的字符集中对URL进行编码?

您应该首先尝试转换字符串的编码。大概是这样的:

$urlencoded = urlencode(mb_convert_encoding('圆通速递','GB2312','UTF-8'));
结果:


%D4%B2%CD%A8%CB%D9%B5%DD首先从UTF-8转换。我需要%D4%B2%CD%A8%CB%D9%B5%DD作为上述最终结果返回%C3%A5%C2%9C%C2%86%C3%A9%C2%80%C2%9A%C3%A9%C2%80%C2%9F%C3%A9%C2%80%C2%92我错过了您的特定字符集,我已经更新了我的问题以匹配它-我认为它返回了您现在正在寻找的内容。mb_*函数支持多字节字符,如日语和中文字符Hanks:)曾经跟踪过一段时间,现在看到了一个贡献的机会Hi@Dagon,谢谢!)非常感谢您的回复:)
echo urlencode(mb_convert_encoding('圆通速递','GB2312',"auto"));