I would like to be able to search a flat text file for $needle and print the entire line if it finds something related.
I have tried the following. It was unsuccessful, as it never returned anything.
$haystack = file("/vol01/www28/htdocs/test/txt.txt");
function array_search_moo ($needle, $haystack, $strict = FALSE) {
for ($int = 0; $int < count($haystack); ++$int) {
if ($strict) {
if ($haystack[$int] === $needle) return $int;
}
else {
if ($haystack[$int] == $needle) return $int;
}
}
return FALSE;
}
(Note that I had to rename array_search to array_search_moo because I could not redefine array_search.)
Am I going about this in a good way, can you see the errors in the script?