views:

953

answers:

1

Hi. I have a problem.

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  A: 

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);
tj111
wapedia.mobi/sv/Gr%C3%B6twas actually working. Sorry, but my PHP script is requesting: Gr%F6t. Why is that? And how can I encode (Gröt) it so it ends up beeing: Gr%C3%B6t.Thank you so much.
Johan
I fixed the problem. It originated from the JavaScript function that passed the string as a GET argument to the PHP file. So I guess this wasn't a PHP question after all, sorry about that.I originally encoded it with the JavaScript escape() function, however, I found that using encodeURIComponent was working much better with UTF-8.Thank you very much for your time and help.
Johan