Basic PHP example: use regular expressions to modify configuration information

Source: Internet
Author: User
Tags php example
: This article mainly introduces the basic example of PHP: use regular expressions to modify the configuration information. if you are interested in the PHP Tutorial, refer to it. Working Principle of various php files:

The following is the code pulling Time:

 

Dbconfig. php

  $ V) {$ info = preg_replace ("/define \ (\" {$ k }\",\"(.*?) \ "\)/", "Define (\" {$ k} \ ", \" {$ v} \ ")", $ info);} // 3. write the replaced information back to the configuration file file_put_contents ("dbconfig. php ", $ info); echo" modified successfully! "; Echo" back ";

Doupdate. php

  "Host", "USER" => "USER", "PASSWORD" => "PASSWORD", "DBNAME" => "database name"); // 1. read the configuration file information $ info = file_get_contents ("dbconfig. php "); // Set dbconfig. read the information in the PHP file and assign it to the info variable // 2. use regular expressions to parse the configuration file information preg_match_all ("/define \(\"(. *?) \",\"(.*?) \ "\)/", $ Info, $ a); // resolve the information in info to a variable for storage // 3. traverse the parsed information and output it to the modified form echo "edit configuration file"; echo "";

Edit. php

The above describes the basic example of PHP: use regular expressions to modify configuration information, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.