Basic PHP example: use a regular expression to modify the configuration information. example: Regular expression _ PHP Tutorial

Source: Internet
Author: User
Basic PHP example: use a regular expression to modify the configuration information. Basic PHP example: use a regular expression to modify the configuration information. In this example, the regular expression is used for various working principles of php: The following is the code pulling Time :? Php configuration file information define (HOST, loca PHP Basic example: use a regular expression to modify the configuration information, sample regular expression

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

Various php Working Principle: The following is the code pulling Time :? Php // define ("HOST", "loca...

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.