如何解析像对象一样的.ini文件源 [英] How to parse .ini file source like objects

查看:78
本文介绍了如何解析像对象一样的.ini文件源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用可调用的设置来解析.ini文件?

Is there a way to parse an .ini file with the settings callable as objects?

$config = parse_ini_file(ABSPATH . '/config.ini', true);

$dbName = $config->database->name;

//instead of
$dbName = $config['database']['name'];

推荐答案

尝试一下.

$config = json_decode(json_encode($config));

现在您可以使用这样的语法.

And now you can use syntax like this.

 $dbName = $config->database->name

这篇关于如何解析像对象一样的.ini文件源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆