i have been trying create page can search .txt file using html , php.
here code:
<?php $file = 'myfile.txt'; if (preg_match_all($pattern, $contents, $matches)) { echo "found matches:\n"; echo implode("\n", $matches[0]); } else { echo "no matches found"; }
please try code. code missing $contents
<?php $file = 'somefile.txt'; $searchfor = 'search text come here'; // file contents $contents = file_get_contents($file); // escape special characters in query $pattern = preg_quote($searchfor, '/'); // regular expression $pattern = "/^.*$pattern.*\$/m"; // search if(preg_match_all($pattern, $contents, $matches)){ echo "found matches:\n"; echo implode("\n", $matches[0]); } else{ echo "no matches found"; }
thanks amit
Comments
Post a Comment