: 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.