It should be more memory than loading a file into an array
foreach (new SplFileObject('filename.txt') as $lineNumber => $lineContent) {
if(trim($lineContent) === 'WANT THIS LINE') {
echo $lineNumber;
break;
}
}
If you just want to find parts of a word, replace
if(trim($lineContent) === 'WANT THIS LINE') {
with
if (FALSE !== strpos($lineContent, 'WANT')) {
source
share