Created
March 9, 2023 18:05
-
-
Save DamChtlv/1ff3c8924aa093c90d3f16c84aa837d2 to your computer and use it in GitHub Desktop.
Latitude Longitude Regex PHP
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 | |
// Get Lat / Long coordinates as separate values | |
$latlong = array(); | |
$str = '-28.0166667, 153.4'; | |
preg_match_all( '/[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)|(90(\.0+)?)/', $str, $matches ); | |
if ( $matches && is_array( $matches ) ) { | |
$matches = reset( $matches ); | |
// Group values by 2 (sometimes we have more than 1 latlong in a cell) | |
$latlong = is_array( $matches ) ? array_chunk( $matches, 2 ) : $matches; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment