Advertisement
scriptz-team

[PHP] SEARCH FOR TEXT iN MULTiPLE FiLES

May 20th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/plain');
  3. /* _____ _____ _ _____ _____ _____ _____ _____ _____
  4. ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  5. |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  6. |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  7. |s C R i P T z - T E A M . i N F O|████████████████████████████
  8.  
  9. $arr -> array of files, for us it was file1.log and file2.log,
  10. dont forget to write the filename without extension, since its
  11. handled in "$file = "./__logs/" . $value . ".log";" so just
  12. replace that extension .log to any you need, like .txt or .sql
  13. */
  14.  
  15. //set_time_limit(0); -> Needed if you searching in big files for long time
  16. //ini_set('memory_limit', '800M'); -> Needed if you searching in big files
  17.  
  18. $arr = array(
  19. "file1",
  20. "file2"
  21. );
  22. foreach ($arr as &$value) {
  23. $file = "./__logs/" . $value . ".log";
  24. $searchfor = '';
  25.  
  26. $contents = file_get_contents($file);
  27. $pattern = preg_quote($searchfor, '/');
  28. $pattern = "/^.*$pattern.*\$/m";
  29. if (preg_match_all($pattern, $contents, $matches)) {
  30. echo "Found:\n";
  31. echo implode("\n", $matches[0]);
  32. } else {
  33. echo "No match!";
  34. }
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement