使用PHP将HTTP POST中的数据放入CSV中?

I'm writing a basic android app that sends GPS data via HTTP POST to a PHP page. I want the data to just be the two values (latitude and longitude) separated by a comma.

<?php
    $myFile = "requestslog.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    fwrite($fh, "
");
    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 the data like 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 it possible for the PHP to replace the '&' with a ','? I'm lookg for the end result to be a csv with those 2 rows. I don't have an experience with PHP and any help would be great.

str_replace('&',',') should do the trick.

If you want to end with just values, you can do following on every line:

str_replace( array( 'lat=', '&long=' ), array( '', ',' ), $sLine );

where $sLine is line from your file.

Complete example:

<?php
$myFile = "requestslog.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, "
");
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>"

?>