Skip to content

Instantly share code, notes, and snippets.

/index.php

Created Mar 10, 2017
Embed
What would you like to do?
<?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