我有一个看起来像这样的txt文件
USER:user46226234 通过:#)(HF(WE * FHWE
USER:user49503420594 通过:黄鸟
USER:user449202934 通过:狗
我正在尝试提取这些对中的每一对并在脚本中使用它们。我不是一个真正的PHP开发人员,在该领域几乎没有技能,但我可以用我的方式处理函数,我知道基本语法。
提前感谢您的关注。
答案 0 :(得分:4)
假设您的密码文件仅包含有效行和空行
编辑:如果您的php配置严格:
$lines = file('file.txt');
$credentials = 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
$credentials[$username] = $password;
}
print_r($credentials);
答案 1 :(得分:0)
查看本教程,我认为写得很好。 http://www.tizag.com/phpT/fileread.php
答案 2 :(得分:0)