store data into a text file using php?

前端 未结 6 1271
有刺的猬
有刺的猬 2021-01-13 14:46

i am trying to store data in a text file, something like an array into a text file using php instead of storing into mysql database.

for example here are the data to

6条回答
  •  不思量自难忘°
    2021-01-13 15:29

    //-- short -------------------------------------------

    $data = [ "a" => "A",  "b" => "B", "c" => "C" ];
      echo '
    data - array: '; var_dump($data); file_put_contents('db.php', json_encode($data) ); //get $g = json_decode(file_get_contents('db.php') , 1); // 1 Array , 0 Object echo '

    short: var_dump($g): '; var_dump($g);

    //-- long -------------------------------------------//

    $data = [ "a" => "A",  "b" => "B", "c" => "C" ];
      echo '
    data - array: '; var_dump($data); echo '
    json_encode($data): '; $jdata = json_encode($data); var_dump($jdata); echo'
    '; file_put_contents('db.php', $jdata); //get $jg = file_get_contents('db.php'); echo ' $jg = file_get_contents(\'db.php\'); $jg : '; var_dump($jg); echo '
    json_decode($jg , 1) //1 Array
    '; $g = json_decode($jg , 1); var_dump($g); echo '
    json_decode($jg , 0) //0 Object
    '; $g = json_decode($jg , 0); var_dump($g);

提交回复
热议问题