MortenMoulder MortenMoulder - 22 days ago 5
PHP Question

file_get_contents() and unicode characters in domain (like æøå)

Whenever I try to grab a page's content using

file_get_contents()
, and the domain has an unicode character in it, I get this:


file_get_contents(https://møller.dk/): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name of service not known in >FILE LOCATION<


This only happens when I have an unicode character in the domain. Here's an example:

file_get_contents("http://møller.dk/");

Answer

You need to use the idn_to_ascii() function:

file_get_contents('http://' . idn_to_ascii('møller.dk'));

Reference: