我有一个.ini文件,看起来像:
password = password123
username = username123
host = host123
在我的 php 中,我想将值"password123"保存到名为 $password 的私有成员变量中,并将"username123"和"host123"的值保存到私有成员变量中。前缀值(密码 = ,用户名 = ,主机 = )永远不会更改,但之后的值可能会更改。我尝试将文件保存到数组并搜索它,但遇到了一些问题。任何帮助都非常感谢
使用 parse_ini_file() 函数:
class Foobar {
private $password, $username, $host;
public function __construct($filename) {
$array = parse_ini_file($filename);
$this->password = $array['password'];
$this->username = $array['username'];
$this->host = $array['host'];
}
}