首页 > Web开发 > 详细

php write_ini_file

时间:2014-04-22 01:41:03      阅读:3810      评论:0      收藏:0      [点我收藏+]

php读ini文件有很方便的pares_ini_file,但是写回去却没有,这里写一个:

bubuko.com,布布扣
function write_ini_file($assoc_arr, $path, $has_sections = FALSE) {
    $content = "";
    if ($has_sections) {
        foreach ($assoc_arr as $key => $elem) {
            $content .= "[" . $key . "]\n";
            foreach ($elem as $key2 => $elem2) {
                if (is_array($elem2)) {
                    for ($i = 0; $i < count($elem2); $i++) {
                        $content .= $key2 . "[] = \"" . $elem2[$i] . "\"\n";
                    }
                } else if ($elem2 == "")
                    $content .= $key2 . " = \n";
                else
                    $content .= $key2 . " = \"" . $elem2 . "\"\n";
            }
        }
    } else {
        foreach ($assoc_arr as $key => $elem) {
            if (is_array($elem)) {
                for ($i = 0; $i < count($elem); $i++) {
                    $content .= $key2 . "[] = \"" . $elem[$i] . "\"\n";
                }
            } else if ($elem == "")
                $content .= $key2 . " = \n";
            else
                $content .= $key2 . " = \"" . $elem . "\"\n";
        }
    }

    if (!$handle = fopen($path, ‘w‘)) {
        return false;
    }
    if (!fwrite($handle, $content)) {
        return false;
    }
    fclose($handle);
    return true;
}
bubuko.com,布布扣

 

php write_ini_file,布布扣,bubuko.com

php write_ini_file

原文:http://www.cnblogs.com/trying/p/3678467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!