3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // --------------------------- DETECT CITY BY IP --------------------------- // function detect_city($ip) { $default = 'UNKNOWN'; if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost') $ip = '8.8.8.8'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $curlopt_useragent, CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1, CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'], ); curl_setopt_array($ch, $curl_opt); $content = curl_exec($ch); if (!is_null($curl_info)) { $curl_info = curl_getinfo($ch); } curl_close($ch); if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) ) { $city = $regs[1]; } if ( preg_match('{<li>State/Province : ([^<]*)</li>}i', $content, $regs) ) { $state = $regs[1]; } if( $city!='' && $state!='' ){ $location = $city . ', ' . $state; return $location; }else{ return $default; } } $ip = '87.224.117.53'; echo detect_city($ip); ?>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/JQh70:15 Stack trace: #0 /in/JQh70(54): detect_city('87.224.117.53') #1 {main} thrown in /in/JQh70 on line 15
Process exited with code 255.
Output for hhvm-3.10.0 - 3.13.2
Notice: Undefined index: HTTP_HOST in /in/JQh70 on line 24 Notice: Undefined variable: curl_info in /in/JQh70 on line 31 Notice: Undefined variable: city in /in/JQh70 on line 44 UNKNOWN
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function curl_init() in /in/JQh70 on line 15
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: curl_init() in /in/JQh70 on line 15
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: curl_init() in /in/JQh70 on line 15
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: curl_init() in /in/JQh70 on line 15