How to parse .ini file source like objects

安稳与你 提交于 2020-02-06 04:46:25

问题


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'];

回答1:


Try this.

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

And now you can use syntax like this.

 $dbName = $config->database->name


来源:https://stackoverflow.com/questions/23321985/how-to-parse-ini-file-source-like-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!