|
发表于 2020-4-19 13:50:13
|
显示全部楼层
安徽省合肥市
按照易语言写配置的形式:
首先在PHP把要保持的配置转为jsonxx形式:
- $json = json_encode(["config" =>["name"=>"user_name","passwd" => "password"]]);
复制代码 输出就是json格式xx:
- {"config":{"name":"user_name","passwd":"password"}}
复制代码 我们来保持xx到php目录:
- file_put_contents("config.json",$json); //在PHP运行目录保持为config.json的配置
复制代码 然后如何读取xx:
- //读取json文件
- $json_data = file_get_contents("config.json");
- //解析jsonxx
- $arr = json_decode($json_data,true);
- //输出相关xx
- echo $arr["config"]["name"];
- echo "\r\n</br>";//换行
- echo $arr["config"]["passwd"];
复制代码 完整代码:
- <?php
- //转xx为json
- $json = json_encode(["config" =>["name"=>"user_name","passwd" => "password"]]);
- //保存为jsonxx文件到当前目录
- file_put_contents("config.json",$json);
- //读取json文件
- $json_data = file_get_contents("config.json");
- //解析jsonxx
- $arr = json_decode($json_data,true);
- //输出相关xx
- echo $arr["config"]["name"];
- echo "\r\n</br>";//换行
- echo $arr["config"]["passwd"];
复制代码
|
|