In php how can I read a text file and get each line into an array?
I found this code which does it, somewhat, but looks for a = sign and I need to look for a new line:
<?PHP
$file_handle = fopen("dictionary.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);
print $parts[0] . $parts[1]. "<BR>";
}
fclose($file_handle);
?>
Well, you could just replace the '=' with a "\n" if the only difference is that you're looking for a newline.
However, a more direct way would be to use the file() function:
$lines = file("dictionary.txt");
That's all there is to it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With