- /**
- Desc: Configuration File
- link:bbs.it-home.org
- Date:2013/2/24
- */
- $name = "admin";//kkkk
- $BB = ' 234 ';
- $db = 4561321;
- $KKK = "admin";
- ?>
Copy CodeFunction definition: Profile data value acquisition: function GetConfig ($file, $ini, $type = "string") Profile data Entry update: function Updateconfig ($file, $ini, $value, $ Type= "string") Call Mode:
GetConfig ("./2.php", "BB");//
- Updateconfig ("./2.php", "KKK", "admin");
Gets the profile data value.
- When the default does not have a third argument, reads the contents of the extracted "in or" from the string
- If there is a third argument, int is treated as a numeric int.
- 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];
- }
- }
Configuration file Data Item update
- The contents of the extract ' in or ' are read by string when there is no fourth parameter by default
- If there is a fourth argument, int is treated as a numeric int.
- function Updateconfig ($file, $ini, $value, $type = "string")
- {
- $str = file_get_contents ($file);
- $str 2 = "";
- if ($type = = "int")
- {
- $str 2 = preg_replace ("/". $ini. "= (. *);/", $ini. " =" . $value. ";", $str);
- }
- Else
- {
- $str 2 = preg_replace ("/". $ini. "= (. *);/", $ini. " =\"" . $value. "\"; ", $str);
- }
- File_put_contents ($file, $str 2);
- }
Echo GetConfig ("./2.php", "BB", "string");
- GetConfig ("./2.php", "BB");//
- Updateconfig ("./2.php", "KKK", "admin");
- echo "
". GetConfig ("./2.php "," Name "," string ");
- ?>
Copy CodeThe following is an improved version
Improve the improved version
- /**
- * link:bbs.it-home.org
- * DATE:2013/2/24
- * Configuration file operation (queried and modified)
- * When the default does not have a third parameter, read the contents of the extract "in or" by string
- * If there is a third argument when int is treated as a numeric int.
- * Call Demo
- $name = "admin";//kkkk
- $BB = ' 234 ';
$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);
- $str 2 = "";
- if ($type = = "int") {
- $str 2 = preg_replace ("/". Preg_quote ($ini). " = (. *);/", $ini." = ". $value."; ", $str);
- }
- else{
- $str 2 = preg_replace ("/". Preg_quote ($ini). " = (. *);/", $ini." =\ "". $value. " \ ";", $str);
- }
- File_put_contents ($file, $str 2);
- }
- ?>
Copy CodeYou may be interested in the article: PHP des encryption decrypted Code One example PHP uses 3DES encrypted code (compatible with. NET) |