3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000 /* 500ms */){ $ret = array(); // get page info from graph $fanpage_data = json_decode(file_get_contents('http://facebook.com/' . $fanpage_name), true); if(empty($fanpage_data['id'])){ // invalid fanpage name return $ret; } $matches = array(); $url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $fanpage_data['id']; $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'))); for($a = 0; $a < $no_of_retries; $a++){ $like_html = file_get_contents($url, false, $context); preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9._-]+)" data-jsid="anchor" target="_blank"}', $like_html, $matches); if(empty($matches[1])){ // failed to fetch any fans - convert returning array, cause it might be not empty return array_keys($ret); }else{ // merge profiles as array keys so they will stay unique $ret = array_merge($ret, array_flip($matches[1])); } // don't get banned as flooder usleep($pause); } return array_keys($ret); } print_r(fetch_fb_fans('ivcrn', 2, 400000)); // prints 73 unique fan names as array
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for facebook.com failed: System error in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): Failed to open stream: php_network_getaddresses: getaddrinfo for facebook.com failed: System error in /in/oE7EI on line 6 Array ( )
Output for 8.0.13 - 8.0.30
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): Failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/oE7EI on line 6 Array ( )
Output for 8.0.0 - 8.0.12
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): Failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/oE7EI on line 6 Array ( )
Output for 5.4.9 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4, 7.0.20, 7.1.5 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.3.32 - 7.3.33, 7.4.0, 7.4.26 - 7.4.33
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/oE7EI on line 6 Array ( )
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.3 - 7.4.25
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/oE7EI on line 6 Array ( )
Output for 5.5.24 - 5.5.32, 5.5.34 - 5.5.35, 5.6.8 - 5.6.17, 5.6.20 - 5.6.28, 7.0.0 - 7.0.3, 7.0.5 - 7.0.6, 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/oE7EI on line 6 Warning: file_get_contents(http://facebook.com/ivcrn): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/oE7EI on line 6 Array ( )

preferences:
205.02 ms | 403 KiB | 261 Q