Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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代码中的所有符号_Php_Encode - Fatal编程技术网

如何解开php代码中的所有符号

如何解开php代码中的所有符号,php,encode,Php,Encode,我想在我的php代码中对所有符号进行编码,比如aéè…。例如: à --> %C3%A0 é --> %C3%A9 è --> %C3%A8 我的代码中有一个示例: $Name = 'Teàst'; $result = file_get_contents('http://example.com/name/' . $Name . ) url必须如下所示:http://example.com/name/Te%C3%A0st 我需要在代码中添加什么?您应该使用urlencode函

我想在我的php代码中对所有符号进行编码,比如
aéè…
。例如:

à --> %C3%A0
é --> %C3%A9
è --> %C3%A8
我的代码中有一个示例:

$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name . )
url必须如下所示:
http://example.com/name/Te%C3%A0st


我需要在代码中添加什么?

您应该使用urlencode函数将字符转换为可以在URL中使用的字符

$Name = utf8_encode('Teàst');
$result = file_get_contents('http://example.com/name/' . urlencode($Name));

更新正如您提到的编码是ASCII而不是UFT-8,您需要先调用utf8_encode将编码从ASCII转换为UFT-8,我已经更新了示例以显示这一点。

可能有一个函数用于此,它不是正确的编码器。结果是
te%E0st
而不是
te%C3%A0st
rawurlencodeencode是否适合您?如果不知道编码,很难说。同样的问题,那是行不通的。对于编码,我想我已经用一个适合你的解决方案更新了我的答案。