Write the array to the file in php and then read it.

Source: Internet
Author: User
Php writes the array to a file, and reads many open-source projects. configuration information of some projects is generally written in the file, and some are written into the constant of the configuration file, some are written to the array. However, those are relatively complex and the array is not studied in depth. I have roughly read the constant. it is generally complicated to modify. First, you need to write the array in php to the file and then read it.
I have seen many open-source projects. configuration information of some projects is generally written in files,
Some are constants written to the configuration file, and some are written to arrays.

However, those are relatively complex and the array is not studied in depth. I have roughly read the constant,
Generally, modification is complicated. First, you need to read all the configuration files,
Then, replace the content through regular expression matching, and then write the content to the file,

The method I used below is relatively simple and easy. I will post the code.

If (isset ($ _ POST ['sub ']) {$ cfg = array ('Contact' = >$ _ POST ['Contact ']); // save the data to the array file_put_contents ('. /data/contact. cache ', serialize ($ cfg); // serialize the array and write it to contact. in the 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 $ this-> assign ('cfg', $ cf ); // send to the foreground template $ this-> display ('other/contact ');}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.