Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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/6/entity-framework/4.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,而不使用urlencode:ing!_Php_Urlencode_File Get Contents - Fatal编程技术网

PHP获取带有特殊字符的url,而不使用urlencode:ing!

PHP获取带有特殊字符的url,而不使用urlencode:ing!,php,urlencode,file-get-contents,Php,Urlencode,File Get Contents,我希望file_get_contents获得如下url: 问题是它请求(抱歉,无法发布整个链接):…您可以看到的wapedia.mobi/sv/Gr%C3%B6t已被URL编码,该页面没有给我任何结果 如何做到这一点?根据l,如果URL包含特殊字符,则必须对其进行专门编码。这意味着函数本身不应该进行特殊编码。您的URL很可能在传递给函数之前已被编码,因此请先通过urldecode进行传递,然后查看发生了什么 编辑:您是说编码出错了。PHP手册再次明确指出,在将URL传递到文件\u get\u c

我希望file_get_contents获得如下url:

问题是它请求(抱歉,无法发布整个链接):…您可以看到的wapedia.mobi/sv/Gr%C3%B6t已被URL编码,该页面没有给我任何结果

如何做到这一点?

根据l,如果URL包含特殊字符,则必须对其进行专门编码。这意味着函数本身不应该进行特殊编码。您的URL很可能在传递给函数之前已被编码,因此请先通过
urldecode
进行传递,然后查看发生了什么

编辑:您是说编码出错了。PHP手册再次明确指出,在将URL传递到
文件\u get\u contents
之前,需要对URL进行编码。尝试对URL进行编码,然后将其传递给函数

$url = urlencode($url);
file_get_contents($url);

mobi/sv/Gr%C3%B6t实际上在工作。很抱歉,我的PHP脚本正在请求:Gr%F6t。为什么呢?我如何对它进行编码(Gröt),使它最终变强:Gr%C3%B6t。非常感谢。我解决了这个问题。它源自JavaScript函数,该函数将字符串作为GET参数传递给PHP文件。所以我想这毕竟不是一个PHP问题,很抱歉。我最初使用JavaScript escape()函数对其进行编码,但是,我发现使用encodeURIComponent可以更好地处理UTF-8。非常感谢您的时间和帮助。谢谢Johan,您使用“encodeURIComponent”的建议对我很有用!