i want find word in line range text file using php. here's text file:
1 asdcasdc 2 asdcadsc 3 asdc found asdcac 4 ascdsc found asd 5 kjhblk 6 kjn 7 found asdcac 8 asdcasd found 9 asdcasdc 10 asdc 11 asdc
i want searching 'found' in range 5-11 of line text file. how output :
7 found asdcac 8 asdcasd found
any appreciated
-php noobie
something trick
$content = file(__dir__ . '/yourfile.txt'); // grab lines want search between // search lines 5-11 $lines = array_slice($content, 5, 6, true); $found = array_filter($lines, function($line) { return strpos($line, 'found') !== false; }); print_r($found);
just change file_get_contents actual file.
also references here's array_slice , array_filter
Comments
Post a Comment