Php array file writing method. A var_export function is provided for us in php, which can directly import php code into a file. Copy the following code to var_export ($ times, true). if it is not added with true, it cannot be written. in php, a function var_export is provided for us. you can directly import the php code to a file.
| The code is as follows: |
|
|
Var_export ($ times, true); the file cannot be written without adding true.
$ Fp = fopen('aa.txt ', 'W + ');
Fwrite ($ fp, var_export ($ times, true ));
Fclose ($ fp ); |
Method 2
Use the serializ and unserialize functions
| The code is as follows: |
|
|
If (isset ($ _ POST ['sub']) {
$ Cfg = array ('Contact '= >$ _ POST ['Contact']); // store data in an array
File_put_contents ('./data/contact. cache', serialize ($ cfg ));
// Serialize the array and write it to contact. cache,
$ This-> redirect ('other/contact'); // jump
}
Else {
$ Fp = fopen ('./data/contact. cache', 'r'); // Read
$ Cf = unserialize (fread ($ fp, filesize ('./data/contact. cache'); // deserialize and assign values
$ This-> assign ('cfg ', $ cf); // send it to the foreground Template
$ This-> display ('other/contact ');
} |
He can directly import php code into a file. The code is as follows: var_export ($ times, true); cannot be written without adding true...