23 December 2008

Code to search within file content

$dirname = '.';
if(is_dir($dirname))
{

if ($handle = opendir('.'))
{
while (false !== ($file = readdir($handle)))
{
if(is_file($file) && $file != "heavyfile.zip")
{
$flhandle = fopen($file, "r");
$contents = fread($flhandle, filesize($file));
fclose($flhandle);
if(stristr($contents,'include("include/leftpart.php");'))
{
$trans = get_html_translation_table(HTML_ENTITIES);
$str = $search;
$encoded = strtr($str, $trans);
$contents = str_replace('"','',$contents);
$contents = str_replace("'",'',$contents);
//$contents = str_replace('“','',$contents);
//$contents = str_replace('”','',$contents);
//$contents = str_replace('’','',$contents);

$encoded = str_replace('"','',$encoded);
$encoded = str_replace("'",'',$encoded);
$encoded = str_replace('“','“',$encoded);
$encoded = str_replace('”','”',$encoded);
$encoded = str_replace('’','’',$encoded);
//echo strip_tags($contents)."
";

if(stristr(strip_tags($contents),$encoded))
{
$pages[$file] = $file;
$arrpages[$file] = $file;
}
}
}

}
}
}

No comments: