Created
June 5, 2017 13:05
-
-
Save anonymous/99e718375ec9ad9bbdd6d4c366a40752 to your computer and use it in GitHub Desktop.
[PHP] Latitude and Longitude in PHP: A Few Useful Practices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$latitude = $_REQUEST['acme-demo-latitude']; | |
$longitude = $_REQUEST['acme-demo-longitude']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$latitude = filter_var( | |
$_REQUEST['acme-demo-latitude'], | |
FILTER_SANITIZE_NUMBER_FLOAT | |
); | |
$longitude = filter_var( | |
$_REQUEST['acme-demo-longitude'], | |
FILTER_SANITIZE_NUMBER_FLOAT | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$latitude = floatval( | |
filter_var( | |
$_REQUEST['acme-demo-latitude'], | |
FILTER_SANITIZE_NUMBER_FLOAT | |
) | |
); | |
$longitude = floatval( | |
filter_var( | |
$_REQUEST['acme-demo-latitude'], | |
FILTER_SANITIZE_NUMBER_FLOAT | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Return false... | |
if ( ! ( is_float( $latitude ) && is_float( $longitude ) ) ) { | |
return false; | |
} | |
// Or throw an exception... | |
if ( ! ( is_float( $latitude ) && is_float( $longitude ) ) ) { | |
throw new Exception('Latitude and longitude are not valid floating point values.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment