File_get_contents () and Unicode characters in the domain (e.g. æøå)

Whenever I try to capture the contents of a page using file_get_contents() and there is a Unicode character in the domain, I get the following:

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

This only happens when I have a Unicode character in a domain. Here is an example:

 file_get_contents("http://møller.dk/"); 
+6
source share
2 answers

You need to use idn_to_ascii() function:

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

Link:

+5
source

You can use punycode that encode / decode IDNA names:

 $Punycode = new Punycode(); $baseUrl = 'ærlig.no'; $url = 'http://'.$Punycode->encode($baseUrl); echo file_get_contents($url); 
+2
source

Source: https://habr.com/ru/post/1012425/


All Articles