1

Well, i'm trying to get the HTML from a certain web page. This web page has UTF-8 characters in its URL and PHP is giving me this error:

Warning: file_get_contents(http://enem.descomplica.com.br/gabarito/enem/2015/dia-1-2a-aplicacao/questoes/dubai-é-uma-cidade-estado-planejada-para/): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp2\htdocs\test\index.php on line 102

Line 102 is:

if($content = file_get_contents($this->link)){

I'm convinced that the problem is actually with the 'é' in the URL because when I try to use this function with an URL that does not contain UTF8 chars in it, it works.

More specifically, the URL without UTF-8 chars that worked is:

http://enem.descomplica.com.br/gabarito/enem/2015/dia-1-2a-aplicacao/questoes/os-nossos-ancestrais-dedicavam-se/

Does anyone know what can I do?

Thanks in advance!

Lucas
  • 69
  • 7
  • you have try to use curl for this? – Broatcast Oct 25 '16 at 00:32
  • Yes, it does not give me errors but it also does not work – Lucas Oct 25 '16 at 00:33
  • have a look here [How do I POST form data with UTF-8 encoding by using curl](http://stackoverflow.com/questions/12489530/how-do-i-post-form-data-with-utf-8-encoding-by-using-curl) and here [linux curl save as utf-8](http://stackoverflow.com/questions/10172327/linux-curl-save-as-utf-8) – Broatcast Oct 25 '16 at 00:36
  • 1
    Possible duplicate of [file\_get\_contents - Special characters in URL - Special case](http://stackoverflow.com/questions/31720418/file-get-contents-special-characters-in-url-special-case) – Manh Nguyen Oct 25 '16 at 00:55

1 Answers1

0

Well, the answer was simpler than I imagined.

Instead of using the raw URL

http://enem.descomplica.com.br/gabarito/enem/2015/dia-1-2a-aplicacao/questoes/dubai-%C3%A9-uma-cidade-estado-planejada-para/

I used the method rawurlencode to encode only the UTF-8 chars like:

$url = "http://enem.descomplica.com.br/gabarito/enem/2015/dia-1-2a-aplicacao/questoes/dubai-" . rawurlencode("é") . "-uma-cidade-estado-planejada-para/";

Now it works!

Lucas
  • 69
  • 7