file io - Putting data from HTTP POST in a CSV with PHP? -
i'm writing basic android app sends gps data via http post php page. want data 2 values (latitude , longitude) separated comma.
<?php $myfile = "requestslog.txt"; $fh = fopen($myfile, 'a') or die("can't open file"); fwrite($fh, "\r\n"); fwrite($fh, file_get_contents('php://input')); fclose($fh); echo "<html><head /><body><iframe src=\"$myfile\" style=\"height:100%; width:100%;\"></iframe></body></html>" ?>
the text file shows data this:
lat=55.020383&lon=-7.1819687 lat=55.020383&lon=-7.1819687 lat=55.020383&lon=-7.1819687 lat=55.0203604&lon=-7.1819732 lat=55.0203604&lon=-7.1819732 lat=55.0203604&lon=-7.1819732
is possible php replace '&' ','? i'm lookg end result csv 2 rows. don't have experience php , great.
str_replace('&',',')
should trick.
if want end values, can following on every line:
str_replace( array( 'lat=', '&long=' ), array( '', ',' ), $sline );
where $sline
line file.
complete example:
<?php $myfile = "requestslog.txt"; $fh = fopen($myfile, 'a') or die("can't open file"); fwrite($fh, "\r\n"); fwrite($fh, str_replace( array( 'lat=', '&lon=' ), array( '', ',' ), file_get_contents('php://input'))); fclose($fh); echo "<html><head /><body><iframe src=\"$myfile\" style=\"height:100%; width:100%;\"></iframe></body></html>" ?>
Comments
Post a Comment