- /**
- Desc: configuration file
- Link: bbs.it-home.org
- Date:
- */
- $ Name = "admin"; // kkkk
- $ Bb = '000000 ';
- $ Db = 4561321;
- $ Kkk = "admin ";
- ?>
Function definition: get the data value of the configuration file: function getconfig ($ file, $ ini, $ type = "string") configuration file data item update: function updateconfig ($ file, $ ini, $ value, $ type = "string") call method:
Getconfig ("./2.php"," bb ");//
- Updateconfig ("./2.php"," kkk "," admin ");
// Obtain the configuration file data value.
- // If no third parameter exists by default, extract the content in ''or" "according to the string
- // If there is a third parameter, int is used.
- Function getconfig ($ file, $ ini, $ type = "string ")
- {
- If ($ type = "int ")
- {
- $ Str = file_get_contents ($ file );
- $ Config = preg_match ("/". $ ini. "= (. *);/", $ str, $ res );
- Return $ res [1];
- }
- Else
- {
- $ Str = file_get_contents ($ file );
- $ Config = preg_match ("/". $ ini. "= \" (. *) \ ";/", $ str, $ res );
- If ($ res [1] = null)
- {
- $ Config = preg_match ("/". $ ini. "= '(. *)';/", $ str, $ res );
- }
- Return $ res [1];
- }
- }
// Update configuration file data items
- // If no fourth parameter exists by default, extract the content in ''or" "according to the string
- // If there is a fourth parameter, int is used.
- Function updateconfig ($ file, $ ini, $ value, $ type = "string ")
- {
- $ Str = file_get_contents ($ file );
- $ Str2 = "";
- If ($ type = "int ")
- {
- $ Str2 = preg_replace ("/". $ ini. "= (. *);/", $ ini. "=". $ value. ";", $ str );
- }
- Else
- {
- $ Str2 = preg_replace ("/". $ ini. "= (. *);/", $ ini. "= \"". $ value. "\"; ", $ str );
- }
- File_put_contents ($ file, $ str2 );
- }
// Echo getconfig ("./2.php"," bb "," string ");
- Getconfig ("./2.php"," bb ");//
- Updateconfig ("./2.php"," kkk "," admin ");
- // Echo"
". Getconfig ("./2.php", "name", "string ");
- ?>
The following are the improved versions.
// Complete the ultimate version
- /**
- * Link: bbs.it-home.org
- * Date:
- * Configuration file operations (query and modification)
- * If no third parameter is provided by default, the content in ''or" "is extracted based on the string.
- * If there is a third parameter, int is used.
- * Call demo
- $ Name = "admin"; // kkkk
- $ Bb = '000000 ';
$ Bb = getconfig ("./2.php"," bb "," string ");
- Updateconfig ("./2.php"," name "," admin ");
- */
- Function get_config ($ file, $ ini, $ type = "string "){
- If (! File_exists ($ file) return false;
- $ Str = file_get_contents ($ file );
- If ($ type = "int "){
- $ Config = preg_match ("/". preg_quote ($ ini). "= (. *);/", $ str, $ res );
- Return $ res [1];
- }
- Else {
- $ Config = preg_match ("/". preg_quote ($ ini). "= \" (. *) \ ";/", $ str, $ res );
- If ($ res [1] = null ){
- $ Config = preg_match ("/". preg_quote ($ ini). "= '(. *)';/", $ str, $ res );
- }
- Return $ res [1];
- }
- }
Function update_config ($ file, $ ini, $ value, $ type = "string "){
- If (! File_exists ($ file) return false;
- $ Str = file_get_contents ($ file );
- $ Str2 = "";
- If ($ type = "int "){
- $ Str2 = preg_replace ("/". preg_quote ($ ini ). "= (. *);/", $ ini. "= ". $ value. ";", $ str );
- }
- Else {
- $ Str2 = preg_replace ("/". preg_quote ($ ini ). "= (. *);/", $ ini. "= \"". $ value. "\"; ", $ str );
- }
- File_put_contents ($ file, $ str2 );
- }
- ?>
Articles you may be interested in: php DES encryption and decryption code example php uses 3des encryption code (compatible with. net) |