This is because you don't even try to parse your data in file. The fact that the file is in PHP makes no sense at all. By reading your file, you don't interpret it as PHP code. Your call to
file_get_contents
returns only the string, nothing else:
http://php.net/manual/en/function.file-get-contents.php[
^].
You need to parse each like (stop formatting it as a PHP file, it won't help you), read each line, parse it into key/value pairs (it depends on format you choose) and add data with keys to the associative array. All PHP arrays are
associative arrays (ordered maps):
http://php.net/manual/en/language.types.array.php[
^].
[EDIT]
If you want to find my first recommendation, you would need to read line by line. Please see some code samples here:
http://stackoverflow.com/questions/6073235/how-to-read-line-by-line-in-php[
^].
Alternatively, you can read all file in the array, but using the function
file
instead:
http://php.net/manual/en/function.file.php[
^].
As documentation says (please see), each line in a file will correspond to an array element. But you need a different array, and array of passwords indexed with file username values.
Then you need to create a new array out of the line array, parsing each separate line into username/password pairs. You can use the method
explode
:
http://php.net/manual/en/function.explode.php[
^].
—SA