PHP读取配置文件,如何实现高效长尾词查询?
- 内容介绍
- 文章标签
- 相关推荐
本文共计219个文字,预计阅读时间需要1分钟。
PHP读取配置文件,操作配置文件(查询与修改)。默认没有第三个参数时,按字符串读取'''或''''中的内容。如果有第三个参数为int时,按数字处理int。调用demo$name=admin;
PHP读取配置文件/** * 配置文件操作(查询了与修改) * 默认没有第三个参数时,按照字符串读取提取''中或""中的内容 * 如果有第三个参数时为int时按照数字int处理。 *调用demo $name="admin"; $bb='234'; $bb=get_config("libs/config.php", "bb"); update_config("libs/config.php", "name", $name); */ 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); }
本文共计219个文字,预计阅读时间需要1分钟。
PHP读取配置文件,操作配置文件(查询与修改)。默认没有第三个参数时,按字符串读取'''或''''中的内容。如果有第三个参数为int时,按数字处理int。调用demo$name=admin;
PHP读取配置文件/** * 配置文件操作(查询了与修改) * 默认没有第三个参数时,按照字符串读取提取''中或""中的内容 * 如果有第三个参数时为int时按照数字int处理。 *调用demo $name="admin"; $bb='234'; $bb=get_config("libs/config.php", "bb"); update_config("libs/config.php", "name", $name); */ 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); }

