PHP saves a piece of data in a TXT file and displays its contents,
The data here can be basic data types, arrays, objects, etc.;
It can be serialized with serialize when it is stored, but it should be deserialized with unserialize first when it is taken.
<?php $data = Array ("Shanghai", "Xian", "Beijing"); Saves the array to the specified text file file_put_contents ("E:/data.txt", Serialize ($data)); Get data $datas = Unserialize (file_get_contents ("E:/data.txt")); Print_r ($datas);? >
Of course, you can also use Json_encode, where the array can be accessed by key-value pairs, which are escaped with Json_decode.
<?php $data = Array ("modern" = "Shanghai", "culture" = "Xi ' an", "capital" = "Beijing"); Saves the array to the specified text file file_put_contents ("E:/data.txt", Json_encode ($data)); Get data $datas = Json_decode (file_get_contents ("E:/data.txt")); Print_r ($datas);? >
http://www.bkjia.com/PHPjc/864477.html www.bkjia.com true http://www.bkjia.com/PHPjc/864477.html techarticle PHP saves a piece of data in a TXT file and displays its contents, where the data can be a basic data type, an array, an object, etc., and can be serialized with serialize when stored ...