| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace Heanup\Frame\Helper;
- /**
- * 文件操作
- */
- class File extends \Heanup\Frame\Helper
- {
- /**
- * 写入ini文件
- * @param string $path
- * @param string|array $data
- * @return int|bool
- */
- public static function writeIniFile($path, $data)
- {
- $content = null;
- foreach ($data as $key => $item) {
- if (is_array($item)) {
- $content .= "\n[{$key}]\n";
- foreach ($item as $k => $v) {
- if (is_numeric($v) || is_bool($v)) {
- $v = '"' . $v . '"';
- }
- $content .= "{$k} = {$v}\n";
- }
- } else {
- if (is_numeric($item) || is_bool($item)) {
- $item = '"' . $item . '"';
- }
- $content .= "{$key} = {$item}\n";
- }
- }
- return file_put_contents($path, $content);
- }
- }
|