Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created March 10, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/89568b4fe1da4bc40598c0b7c4acee1c to your computer and use it in GitHub Desktop.
Save anonymous/89568b4fe1da4bc40598c0b7c4acee1c to your computer and use it in GitHub Desktop.
<?php
require "searchfile.php";
$word = 'palavra';
$files = array('servicos.php', 'contato.html');
$search = new SearchFile($word, $files);
print_r($search->getResults());
<?php
class SearchFile
{
private $files;
private $search;
private $results;
public function __construct($search, $files=array())
{
$this->search = $search;
$this->files = $files;
$this->execute();
}
public function execute()
{
foreach ($this->files as $file) {
if (file_exists($file)) {
$string = file_get_contents($file);
if (stristr($string, $this->search) == true) {
$this->results[] = $file;
}
}
}
}
public function getResults()
{
return $this->results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment