I'm trying to read lines from a txt file and return every line that has a certain string on it. In this case I'm looking for "1992"
alt.txt
1223 abcd
1992 dcba
1992 asda
file.php
function getLineWithString($fileName, $str) {
$lines = file($fileName);
foreach ($lines as $lineNumber => $line) {
if (strpos($line, $str) !== false) {
return $line;
}
}
return -1;
}
When I run the php, I get "1992 dcba" as the return, when I want to receive an array with each line. $line[0] would be "1992 dcba" and $line[1] would be "1992 asda". How could I do this?