I want to extrect all usernames and passwords each from his file and output it nicely. I wrote a code on my appserv 2.5.1 on my computer but only the last loop gave the username output. Tested the code on other machines and it worked perfectly. Dont know what is the problem ...
usernames.txt content :
user1
user2
user3
passwords.txt content :
pass1
pass2
pass3
script content :
$usernames = explode("\n", file_get_contents("usernames.txt"));
$passwords = explode("\n", file_get_contents("passwords.txt"));
foreach( $usernames as $username )
{
foreach( $passwords as $password )
{
echo $username.":".$password."\n";
}
}
output :
:pass1
:pass2
:pass3
:pass1
:pass2
:pass3
user3:pass1
user3:pass2
user3:pass3
var_dump($usernames)and see if it contains what it is supposed to contain.forloop. I'd also suggest that you consider not storing usernames and passwords in separate text files... why not store in a database, or if absolutely necessary, in a file separated by a delimiter (e.g., a CSV file). That way, you'd make sure the usernames and passwords were always stored together properly.var_dump()? Because your code works perfectly fine, the problem might be with theexplode(). It is possible than the line separator is a \r\n instead of a \n. That would explain why it works on some machines and not others.