3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // some address values $client_address = '11010 Langton Arms Court'; $client_city = 'Oakton'; $client_state = 'VA'; $client_zip = '22124'; // building the JSON URL string for Google API call $g_address = str_replace(' ', '+', trim($client_address)).","; $g_city = '+'.str_replace(' ', '+', trim($client_city)).","; $g_state = '+'.str_replace(' ', '+', trim($client_state)); $g_zip = isset($client_zip)? '+'.str_replace(' ', '', trim($client_zip)) : ''; $g_addr_str = $g_address.$g_city.$g_state.$g_zip; $url = "http://maps.google.com/maps/api/geocode/json? address=$g_addr_str"; // Parsing the JSON response from the Google Geocode API to get exact map coordinates: // latitude , longitude (see the Google doc. for the complete data return here: // https://developers.google.com/maps/documentation/geocoding/.) $jsonData = file_get_contents($url); $data = json_decode($jsonData); $xlat = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'}; $xlong = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'}; echo $xlat.",".$xlong;
based on Xcp1i
Output for 7.2.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/tPXWE on line 23 Warning: file_get_contents(http://maps.google.com/maps/api/geocode/json? address=11010+Langton+Arms+Court,+Oakton,+VA+22124): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/tPXWE on line 23 Notice: Trying to get property 'results' of non-object in /in/tPXWE on line 27 Notice: Trying to get property 'geometry' of non-object in /in/tPXWE on line 27 Notice: Trying to get property 'location' of non-object in /in/tPXWE on line 27 Notice: Trying to get property 'lat' of non-object in /in/tPXWE on line 27 Notice: Trying to get property 'results' of non-object in /in/tPXWE on line 28 Notice: Trying to get property 'geometry' of non-object in /in/tPXWE on line 28 Notice: Trying to get property 'location' of non-object in /in/tPXWE on line 28 Notice: Trying to get property 'lng' of non-object in /in/tPXWE on line 28 ,
Output for 5.3.22 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4, 7.0.20, 7.1.5 - 7.1.10
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/tPXWE on line 23 Warning: file_get_contents(http://maps.google.com/maps/api/geocode/json? address=11010+Langton+Arms+Court,+Oakton,+VA+22124): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/tPXWE on line 23 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 ,
Output for 5.5.24 - 5.5.32, 5.5.34 - 5.6.17, 5.6.20 - 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/tPXWE on line 23 Warning: file_get_contents(http://maps.google.com/maps/api/geocode/json? address=11010+Langton+Arms+Court,+Oakton,+VA+22124): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/tPXWE on line 23 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 27 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 Notice: Trying to get property of non-object in /in/tPXWE on line 28 ,