Home » PHP » JS, PHP uses regular expressions to parse GPS data

JS, PHP uses regular expressions to parse GPS data

Shaped like (116.414922,40.035715,0.0) (116.415122,40.035715,0.0) (116.415122,40.035515,0.0) (116.414922,40.035515,0.0)... This data can parse data
with regular expressions





in PHP
$result = array ();
Preg_match_all ([/ (d{0,3}.d{1,6}) *) /, $gps[' gps']; $result);
Foreach ($result[0], as, $row2) {
$res = 0;
Preg_match_all ("/d{1,3}.d{1,6}/", "$row2", "$res");
$gps_array = array (); there are 3 data in //gps_array: longitude, latitude, and elevation
Foreach ($res[0], as, $row3) {
Array_push ($gps_array, $row3);
}
}







in JS
var gps_array = gps.match (/ (d{0,3}.d{1,6}) *) /g;
Var sub1 = new, Array ();
For (VaR J = 0; J < gps_array.length; j++) {
Var gps_array1 = gps_array[j].match (/d{1,3}.d{1,6}/g);
Var sub2 = new, Array ();
For (VaR k = 0; K < gps_array1.length; k++) {
Sub2.push (gps_array1[k]);
}
Sub1.push (sub2);
}





copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest