PHP get url with special characters without urlencode:ing them!

浪尽此生 提交于 2019-12-31 02:57:10

问题


I would like file_get_contents to get a url that looks like this: http://wapedia.mobi/sv/Gröt

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.

How can I do this?


回答1:


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.

Edit: 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);


来源:https://stackoverflow.com/questions/1174189/php-get-url-with-special-characters-without-urlencodeing-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!