O codigo completo para quem puder me ajudar. <html>
<head></head>
<body>
<?php
error_reporting(0);
$ftexto = $_REQUEST['ftexto'];
$fano = $_REQUEST['fano'];
echo "<H1> Arquivos que contenham o texto: " . $ftexto."</H1>";
$dir = "./PDF/$fano/";
$dh = opendir($dir);
$flagEncontrado=false;
while (false !== ($filename = readdir($dh))) {
if (substr($filename,-4) == ".txt") {
$filename2 = "./PDF/$fano/".$filename;
$arquivo = file_get_contents($filename2);
$ocorrencias0 = substr_count($arquivo, $ftexto);
if ($ocorrencias0 !=0)
{
$file=fopen("C:\\wamp\\www\\Arquivos\\PDF\\$fano\\$filename","r");
$filename = str_replace("txt","pdf",$filename);
$filename2 = str_replace("txt","pdf",$filename2);
echo " <br><a href= ".$filename2."> ".$filename." </a>";
echo " <br>Total de ocorrências encontradas: " . $ocorrencias0 . "<br>";
$flagEncontrado=true;
};
while (!feof($file)) // exibir todo txt
{
$linha = fgets($file,4096); // exibir todo txt
echo $linha."<br>"; // exibir todo txt
}
}
}
fclose($file);
if ($flagEncontrado==false)
{echo " <br>Não foi encontrada nenhuma ocorrência da palavra <b>$ftexto</b> no ano de <b>$fano</b> .<br>";}
?>
</body>
</html>