douci1196 2015-02-05 00:19
浏览 84
已采纳

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

No matter what I have tried nothing solve my problem a php file receiving content with defined variables like that

<?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);


?>

When I see the content of activities , I always see Array()Array()Array()Array()

No matter, what I tried to change the array type to string or text by using * implode ,var_export, print_r functions

I always see the Array()Array()Array()Array() written inside the created log file. When I write the echo $content; It seems realy fine.

What am I missing ? IS there anyone experienced the same problem?

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • drtohng5613 2015-02-09 13:56
    关注

    Actually I realized that only using the json_encode function solved my problem and started to turn the array json data to a string format which file_put_content works . Here you can the working complete code for me. Btw there was not any problem with concatenation using the lines $content=$content."" it sill works.

    <?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."
    ";
    //file_put_contents($file, $content, FILE_APPEND);
    
    $fp=fopen($file,"a");
    fputs($fp,$content);
    fclose($fp);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效