php將擷取的數組變成字串傳入txt文本。。。

來源:互聯網
上載者:User

標籤:files   寫入   檔案   json   編碼   txt文本   font   contents   decode   

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

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

php將擷取的數組變成字串傳入txt文本。。。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.