我有一个文件(passwords_admin.txt),其中包含如下信息:
# This file is for storing administrative
# .passwords_user in the same directory.
#
# NOTE (Important):
# format: <server type> <keyword>[,<keyword>...] <server name> <login name> <password>
[<location> [<host> <port>] ]
# The first entry for a given server will be the default user.
# Current keywords:
# livepw - The password change script will change the sa password on this server to the
new live password
# devpw - The password change script will change the sa password on this server to the
new dev password
## mysql servers
##
# Do not remove the next line
# ----------- MySQL Instances start here ----------
mysql 1515,dev,devpw,online,ldap_pwd dev-exodus-01 dba_admin B66AF9 166.77.177.241 3306
mysql 1515,dev,devpw,online,ldap_pwd dev-exodus-01 dba_query 83939E 166.77.177.241 3306
mysql 1515,dev,devpw,online,ldap_pwd qa-exodus-01 dba_admin B66AF9 166.77.189.125 3306
mysql 1515,dev,devpw,online,ldap_pwd qa-exodus-01 dba_query 583939E 166.77.189.125 3306
...
...
数据以这种格式存储:format: <server type> <keyword>[,<keyword>...] <server name> <login name> <password> [<location> [<host> <port>] ]
现在,我想复制和打印特定实例的主机名和关键字(devpw 或 livepw)。
例如,例如 dev-exodus-01。我想打印它的主机名 166.77.177.241 和它的关键字devpw
。或者有什么方法可以将这些值存储在变量中,以后可以使用它们?
我试过这个,但显然它不起作用。
$file = fopen("passwords_admin.txt", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof($file)) {
$line = fgets($file, 1024);
if (preg_match("@devpw(.*)@i", $line, $out)) {
$title = $out[1];
echo $title;
echo "<br/>";
}
}
有什么建议么 ?