欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php中將一段數(shù)據(jù)存到一個(gè)txt文件中并顯示其內(nèi)容

 更新時(shí)間:2014年08月15日 22:13:42   投稿:mdxy-dxy  
這篇文章主要介紹了php中將一段數(shù)據(jù)存到一個(gè)txt文件中,并獲取其內(nèi)容顯示的實(shí)現(xiàn)代碼,需要的朋友可以參考下

這里的數(shù)據(jù)可以為基本數(shù)據(jù)類型,數(shù)組,對(duì)象等;

在存儲(chǔ)的時(shí)候可以用serialize進(jìn)行序列化,但取的時(shí)候要先用unserialize反序列化。

<?php
  $data = array("上海","西安","北京");

  //將數(shù)組存到指定的text文件中
  file_put_contents("E:/data.txt",serialize($data));
  //獲取數(shù)據(jù)
  $datas = unserialize(file_get_contents("E:/data.txt"));
  print_r($datas);
?>

當(dāng)然也可以使用json_encode,這里數(shù)組可以以鍵值對(duì)存取,取時(shí)要用json_decode轉(zhuǎn)義。

<?php
  $data = array("現(xiàn)代"=>"上海","文化"=>"西安","首都"=>"北京");

  //將數(shù)組存到指定的text文件中
  file_put_contents("E:/data.txt",json_encode($data));
  //獲取數(shù)據(jù)
  $datas = json_decode(file_get_contents("E:/data.txt"));
  print_r($datas);
?>

相關(guān)文章

最新評(píng)論