为什么这只显示最后的用户名和密码?在人们开始抱怨将密码存储在文本文件等之前。我只是为了测试目的而这样做。实际上不会将这些密码存储在文本文件中。
$lines = file('users.txt');
$userlist = array();
foreach($lines as $line) {
if(empty($line)) continue;
// whole line
$line = trim(str_replace(": ", ':', $line));
$lineArr = explode(' ', $line);
// username only
$username = explode(':', $lineArr[0]);
$username = array_pop($username);
// password
$password = explode(':', $lineArr[1]);
$password = array_pop($password);
// putting them together
$userlist[$username] = $password;
}
$user = $username;
$pass = $password;
echo "$user";
echo " $pass";