I am new to PHP, and am working on a GPS tracking system. I have to split the GPS codes to store in MySQL.
7/3/2010 5:38:18 AM Posted <!355801020193357*1*1-1*03/07/10,05:38:27*1144.4633*07921.6860*41.6*N*E*48.9*0.8*20,54,6678;47,ffff;12,ffff*1*1*0*363*0*1*27312*529#>
I want:
7/3/2010
5:38:18 AM
355801020193357
1144.4633
07921.6860
48.9
How can I parse out those values from my input?
this code does actually what you would like:
$posted = "7/3/2010 5:38:18 AM Posted <!355801020193357*1*1-1*03/07/10,05:38:27*1144.4633*07921.6860*41.6*N*E*48.9*0.8*20,54,6678;47,ffff;12,ffff*1*1*0*363*0*1*27312*529#>";
preg_match("'(.*?)[<]!(.*?)[>]'is",$posted,$n);
$time = explode(" ",$n[1]);
echo $time[0]."<br />";
echo $time[1]." ".$time[2]."<br />";
$coords = explode("*",$n[2]);
echo $coords[0]."<br />";
echo $coords[4]."<br />";
echo $coords[5]."<br />";
echo $coords[9]."<br />";
The $coords
variable holds the other information too, if needed.
you could use this as to simplify the gps code first
http://www.php.net/manual/en/function.substr.php
and then u could use http://www.php.net/manual/en/function.explode.php to explode based on *
Try using substr function
Reference: http://php.net/manual/en/function.substr.php