MortenMoulder MortenMoulder - 9 months ago 38
PHP Question

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

Whenever I try to grab a page's content using

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

file_get_contents(https://mø 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:


Answer Source

You need to use the idn_to_ascii() function:

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