I have text file with some stuff that i would like to put into array. That text file has one value per line. How do i put each line into array?
use the file() function - easy!
$lines=file('file.txt');
If you want to do some processing on each line, it's not much more effort to read it line by line with fgets()...
$lines=array();
$fp=fopen('file.txt', 'r');
while (!feof($fp))
{
$line=fgets($fp);
//process line however you like
$line=trim($line);
//add to array
$lines[]=$line;
}
fclose($fp);
use file()
http://se2.php.net/manual/en/function.file.php
$fileArr = file("yourfile.txt")
http://www.php.net/manual/en/function.file.php
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