zoukankan      html  css  js  c++  java
  • php 关于php创建 json文件 和 对文件增删改查 示例

     1 <?php
     2 //fopen($file,'w'); //打开文件/创建文件
     3 //file_put_contents($file,$content)//写入文件
     4 //file_get_contents($file)//读取文件
     5 //json_encode();//对变量json编码
     6 //json_decode();//对 JSON 解码
     7 //json_last_error();//返回最后发送的错误
     8 
     9 $arr=array('1','2','3');
    10 $file='../json/dom.json';
    11 $set=file_put_contents($file,json_encode($arr));
    12 var_dump($set);
    13 $get=file_get_contents($file);
    14 $msg=json_decode($get);
    15 var_dump($msg);
    16 echo $msg['0'];
    17 fopen('../json/dom2.json','a');
    18 /* $msg=json_decode($file,true);
    19 var_dump($msg);
    20 print_r($msg); */
    21 /* $arr=array('name'=>'lizi','age'=>'24');
    22 
    23 $jsonArr=json_encode($arr);
    24 
    25 $phpArr=json_decode($jsonArr);
    26 
    27 var_dump(is_object($phpArr));
    28 
    29 print_r($phpArr->name);
    30 
    31 echo '<br />'.gettype($phpArr); */
    32 ?>
  • 相关阅读:
    命令行
    作业三C++
    作业二
    0003---简单的a+b问题
    0002---五层小山
    0001---Hello world
    关于OJ的那些事
    CDQ分治学习笔记
    C++ IO的一些注意点
    Vscode配置C++环境
  • 原文地址:https://www.cnblogs.com/weihexinCode/p/12318366.html
Copyright © 2011-2022 走看看