关于php:php生成配置文件configphp-生成数组配置文件

在很多我的项目中,配置文件是不可短少的,个别配置文件会用变量或者数组进行设置,例如数据库、或者一些公共参数。

创立

<?php

// 配置文件数组
$config = array(
    'DB_URL' => 'localhost',
    'DB_USER' => 'root',
    'DB_PWD' => 'root',
    'DB_NAME' => 'test_db'
);

// 代码格局
$str = '<?php'.PHP_EOL.'/**'.PHP_EOL.'* 配置文件'.PHP_EOL.'* TANKING'.PHP_EOL.'* '.date('Y-m-d').''.PHP_EOL.'*/'.PHP_EOL.'$db_config = '.var_export($config,true) .PHP_EOL.'?>';

// 创立文件
$file = fopen("array.php","w");
echo fwrite($file,$str);
fclose($file);

?>

配置文件

<?php
/**
* 配置文件
* TANKING
* 2021-04-25
*/
$db_config = array (
  'DB_URL' => 'localhost',
  'DB_USER' => 'root',
  'DB_PWD' => 'root',
  'DB_NAME' => 'test_db',
)
?>

作者

Author:TANKING
DateL2021-04-25
WeChat:sansure2016
Web:http://www.likeyun.cn

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理