将数组值转换为可写字符串到从 $_GET 函数传入的文本文件


converting array value to string writable to text file incoming from $_GET function

无论我尝试什么都没有解决我的问题一个PHP文件,接收具有定义变量的内容,如下所示

<?php
$user_id=$_GET["user_id"];
$platform=$_GET["platform"];
$devicemodel=$_GET["devicemodel"];
$deviceuuid=$_GET["deviceuuid"];
--------
and then
$content =$content. " ".$user_id;
$content =$content. " ".$platform;
$content =$content. " ".$devicemodel;
$content =$content. " ".$deviceuuid;

$file = "activities.log"; 
file_put_contents($file, $content);

?>

当我看到活动内容时,我总是看到

Array()Array()Array()Array()Array()

不管怎样,我试图通过使用将数组类型更改为字符串或文本* 内爆、var_export、print_r功能

我总是看到 Array()Array()Array()Array

()Array() 写在创建的日志文件中。当我写回声$content时;看起来还不错。

我错过了什么?有没有人遇到同样的问题?

提前谢谢。

编辑:您需要向我们提供您正在使用代码的方法,如果是形式,还是通过href方法。

但是,我在下面给出的答案只是部分正确。其余的将取决于您向我们提供您使用它的方式。

否则,我将删除此答案。


原答案

每次传递时,您都会不断覆盖$content =$content

因此,您需要$content .=$content连接它,但不是第一个。

这是我对此进行测试的,并取得了成功:

<?php
$_GET["user_id"] = "ID";
$_GET["platform"] = "Platform";
$_GET["devicemodel"] = "Model";
$_GET["deviceuuid"] = "UUID";
$user_id= $_GET["user_id"];
$platform= $_GET["platform"];
$devicemodel= $_GET["devicemodel"];
$deviceuuid= $_GET["deviceuuid"];
$content =$content. " ".$user_id;
$content .=$content. " ".$platform;
$content .=$content. " ".$devicemodel;
$content .=$content. " ".$deviceuuid;
$file = "activities.log"; 
file_put_contents($file, $content);
?>

您可能还希望在写入的每一行之后添加'n,否则如果这是您想要的结果,它将最终成为一长行。

编辑:

根据Ghost在评论中所说的,使用:

$content = "$user_id $platform $devicemodel $deviceuuid";

而不是所有这些额外的变量。

对我来说输出很好。试试这个,看看你是否仍然有同样的问题:

<?php
$_GET["user_id"] = "user_id";
$_GET["platform"] = "platform";;
$_GET["devicemodel"] = "device_model";;
$_GET["deviceuuid"] = "device_uuid";;
$user_id = $_GET["user_id"];
$platform = $_GET["platform"];
$devicemodel = $_GET["devicemodel"];
$deviceuuid = $_GET["deviceuuid"];
/*
and then
*/

$content = $content. " ".$user_id;
$content .= " ".$platform;
$content .= " ".$devicemodel;
$content .= " ".$deviceuuid;

$file = "activities.log"; 
file_put_contents($file, $content);
?>

如果这对您有用,那么问题出在您的代码上。如果这对您不起作用,那么这就是您的 PHP 安装。

编辑:弗雷德刚刚打败了我!

实际上我意识到仅使用 json_encode 函数解决了我的问题,并开始将数组 json 数据转换为file_put_content有效的字符串格式。在这里,您可以为我提供工作完整的代码。顺便说一句,使用行 $content=$content."进行连接没有任何问题。

<?php 
$content ="--başlık--".json_encode($_GET["title"]);
$emails="--email--".json_encode($_GET["user_email"]);
$tarih="--tarih--".json_encode($_GET["tarih"]);
$categori= "--kategori--".json_encode($_GET["kategori"]);
$picturename="--picturename--".json_encode($_GET["picturename"]);
$username="--username--".json_encode($_GET["username"]);
$user_id="--userid--".json_encode($_GET["user_id"]);
$platform="--platform--".json_encode($_GET["platform"]);
$devicemodel="--devicemodel--".json_encode($_GET["devicemodel"]);
$deviceuuid="--deviceuuid--".json_encode($_GET["deviceuuid"]);

$content =$content." ".$tarih;
$content =$content." ".$emails;
$content =$content. " ".$user_id;
$content =$content. " ".$username;
$content =$content. " ".$categori;
$content =$content. " ".$platform;
$content =$content. " ".$devicemodel;
$content =$content. " ".$deviceuuid;
$content =$content. " ".$picturenam;
$file = "/*******/public_html/testupload/logs/logs-tarih-".date("Ymd").".log"; 
$content ="date---".date("F j, Y, g:i a")."--".$content."'n";
//file_put_contents($file, $content, FILE_APPEND);
$fp=fopen($file,"a");
fputs($fp,$content);
fclose($fp);