在PHP中,可以使用parse_ini_file()函数来读取INI配置文件。
以下是使用parse_ini_file()函数读取INI配置文件的示例代码:
$config = parse_ini_file('config.ini');// 读取配置文件中的值$host = $config['host'];$username = $config['username'];$password = $config['password'];// 输出配置文件的值echo "Host: $host\n";echo "Username: $username\n";echo "Password: $password\n";在上面的示例代码中,parse_ini_file()函数接受一个INI配置文件的路径作为参数,并返回一个包含配置文件内容的关联数组。然后,可以像访问普通的关联数组一样,通过键名来访问配置文件中的值。
假设config.ini文件的内容如下:
host=localhostusername=adminpassword=123456运行上面的示例代码,将输出以下内容:
Host: localhostUsername: adminPassword: 123456 
