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

使用PHP将HTTP POST中的数据放入CSV?,php,file-io,replace,Php,File Io,Replace,我正在编写一个基本的android应用程序,通过HTTP POST将GPS数据发送到PHP页面。我希望数据只是由逗号分隔的两个值(纬度和经度) <?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'));

我正在编写一个基本的android应用程序,通过HTTP POST将GPS数据发送到PHP页面。我希望数据只是由逗号分隔的两个值(纬度和经度)

<?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>"

?>
PHP是否可以用“,”替换“&”?我希望最终的结果是这两行的csv。我没有使用PHP的经验,任何帮助都会很好。

应该可以

如果只想以值结束,可以在每一行执行以下操作:

str_replace( array( 'lat=', '&long=' ), array( '', ',' ), $sLine );
其中,
$sLine
是文件中的行

完整示例:

<?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>"

?>

太棒了!非常感谢。本以为它暂时不起作用,但看到你写了“&long=”而我的变量是“&lon”。有了这个改变,效果非常好。非常感谢!
<?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>"

?>