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

0次阅读

共计 616 个字符,预计需要花费 2 分钟才能阅读完成。

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

创立

<?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

正文完
 0