zoukankan      html  css  js  c++  java
  • php将获取的数组变成字符串传入txt文本。。。

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    json_decode($string[, $assoc = false]):对 JSON 格式的字符串进行解码

    1.string:待解码的字符串。

    2.bool类型,为true时返回array而非object。

    json_encode($value):对变量进行json编码。

    file_get_contents($filename):将整个文件读入一个字符串。

    file_put_contents($filename,$data):将一个字符串写入文件。

    1.filename:将要写入数据的文件名。

    2.data:要写入的数据。

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    首先:先把txt原来有的读出来

    $temStr=file_get_contents("files/user.txt");

    接着:将获取出来的json变成数组

    $tempArray=json_decode($temStr,true);

    然后:合并原来的数组和你要传入新的数组。

    $newnewArray=array_merge($tempArray,$newArray);

    然后将数组转成json串

    $jsonStr=json_encode($newnewArray);

    最后:将json写入文件

    file_put_contents("files/user.txt",$jsonStr);

  • 相关阅读:
    APP兼容性测试
    APP本地服务安全测试
    接口安全测试
    Python之日志操作(logging)
    Python之json编码
    Python之配置文件读写
    windows10 修改远程连接本地端口
    ctf学习
    telnet常见的错误
    连接ssh中常见的错误代码
  • 原文地址:https://www.cnblogs.com/chencuixin/p/6567530.html
Copyright © 2011-2022 走看看