Created
January 22, 2014 08:34
-
-
Save mingyun/8555348 to your computer and use it in GitHub Desktop.
php编辑配置文件ini格式文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function put_ini_file ( $file , $array , $i = 0 ){ | |
$str = "" ; | |
foreach ( $array as $k => $v ){ | |
if ( is_array ( $v )){ | |
$str .= str_repeat ( " " , $i * 2 ). "[ $k ]" . PHP_EOL ; | |
$str .= put_ini_file ( "" , $v , $i + 1 ); | |
}else | |
$str .= str_repeat ( " " , $i * 2 ). " $k = $v " . PHP_EOL ; | |
} | |
if( $file ) | |
return file_put_contents ( $file , $str ); | |
else | |
return $str ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment