Each PHP working principle diagram:
Here is the time to pull the code:
PHP/ /config file information define// hostname define("USER", "rootaaaa"); // User name Define ("PASSWORD", "root123456"); // Password Define ("DBNAME", "mydb"); // Database name
dbconfig.php
PHP// Execute configuration file modification operation//1. Read the configuration file information $infofile_get_contents("dbconfig.php"); // 2. Post traversal, and regular substitution of profile information foreach ($_postas$k$v) { $info=preg_replace ("/define\ (\" {$k}\ ", \" (. *?) \ "\)/", "define (\" {$k}\ ", \" {$v}\ ")",$info);} // 3. Write the replacement information back into the configuration file file_put_contents ("dbconfig.php",$info); Echo "Modified successfully!
"; Echo "Return";
doupdate.php
PHP// Edit configuration file $keyinfo=array("host" + "hosts", "User" + "users", "PASSWORD" and "=" Password "," DBNAME "=" database name "); // 1. Read the configuration file information $info file_get_contents ("dbconfig.php"); // the information in the dbconfig.php file is read out and assigned to the info variable//2. Using regular expressions To resolve configuration file information Preg_match_all ("/define\" (. *?) \",\"(.*?) \ "\)/",$info,$a); // parses the information in info into the A variable to store//3. Iterates through the parsed information and outputs it to the modification form Echo "Editing a configuration file
"; Echo "";
edit.php
The above describes the PHP basic example: using regular expressions to modify configuration information, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.