问题描述
我希望file_get_contents获得一个类似于以下内容的网址: http://wapedia. mobi/sv/Gröt
I would like file_get_contents to get a url that looks like this: http://wapedia.mobi/sv/Gröt
问题是它要求(无法发布整个链接,对不起):... wapedia.mobi/sv/Gr%C3%B6t您可以看到它已经被urlencoded了,该页面没有给我任何结果
The problem is that it requests (can't post entire link, sorry): ...wapedia.mobi/sv/Gr%C3%B6t which you can see has been urlencoded, that page does not give me any results.
我该怎么做?
推荐答案
根据 PHP手册 l,如果其中包含特殊字符,则必须对URL进行专门编码.这意味着函数本身不应该进行特殊编码.您的URL很可能在传递给函数之前被 编码,因此请先通过urldecode
传递URL,然后看看会发生什么.
According to the PHP manual, you must specifically encode a URL if it contains special characters. This means the function itself should do no special encoding. Most likely your URL is being encoded before being passed to the function, so pass it through urldecode
first and see what happens.
编辑:您是在说编码混乱了.同样,PHP手册再次明确指出,在将URL传递给file_get_contents
之前,需要对其进行编码.尝试对URL进行编码,然后将其传递给函数.
You're saying the encoding is being messed up. Again the PHP manual specifically states that you need to encode urls prior to passing them to file_get_contents
. Try encoding the URL, then passing it to the function.
$url = urlencode($url);
file_get_contents($url);
这篇关于PHP获取带有特殊字符的url,而无需urlencode:对其进行编码!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!