tt - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of tt.php
- <?php
- // Function to validate a location using the Google Maps Geocoding API
- function validateLocation($location) {
- $apiKey = 'your_api_key'; // Replace with your own Google API key
- // Replace spaces with "+" in the location for URL compatibility
- $location = str_replace(" ", "+", $location);
- $url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$location."&key=".$apiKey;
- $response = file_get_contents($url);
- $data = json_decode($response);
- $status = $data->status;
- if ($status == "OK") {
- return true; // Valid location
- } else {
- return false; // Invalid location
- }
- }
- // Usage example:
- $location = "1600 Amphitheatre Parkway, Mountain View, CA";
- if (validateLocation($location)) {
- echo "Valid location";
- } else {
- echo "Invalid location";
- }
- ?>
File Description
- tt
- PHP Code
- 27 May-2023
- 862 Bytes
You can Share it:
Latest PHP Pastes