How do I read each line from a file in php?

authentication, file, php

Solution

You can use the `file()` function.

foreach(file("data.txt") as $line) {
    // do stuff here
}

Problem

I'm new to learning php and in one of my first programs I wanted to make a basic php website with login capabilities with and array of the user and passwd. my idea is to store the username as a list parameter and have the passwd as the contents, like this: ``` arr = array(username => passwd, user => passwd); ``` now my problem is that I don't know how I can read from the file (`data.txt`) so I can add it into the array. ``` data.txt sample: username passwd anotherUSer passwd ``` I've opened the file with `fopen` and stored it in `$data`.

Original source

Related problems