// Den eingegebenen String in den Dateien des Verzeichnisses suchen
if (isset($SEARCH))
{
$SEARCHUP = htmlentities(trim($SEARCH)) ;
$SEARCHUP = strtoupper($SEARCHUP) ;
// Mehrere Suchbegriffe durch blank getrennt
$aSearch = explode(" ", $SEARCHUP) ;
$nSearch = count($aSearch) ;
$hDir=opendir('.');
$nFound = 0 ;
while (false !== ($cFile = readdir($hDir)))
{
// Verzeichnisse nicht weiter untersuchen ...
// ggf in Verzeichnissen weitersuchen
if (is_dir($cFile))
continue ;
if ($cFile != "." && $cFile != "..")
{
// Debug
//echo "$cFile
\n";
// ### Nur dateien, dernen Name "X" enthaelt
$pos = strpos (strtoupper($cFile), "X");
if ($pos === false)
{ // note: three equal signs
// not found...
continue ;
}
// Komplette Datei einlesen
$nFileSize = filesize($cFile) ;
// $aZeilen = file ($cFile);
$hFile = fopen($cFile, "r") ;
$cFileContent = fread($hFile, $nFileSize) ;
fclose($hFile) ;
$cFileContent = strip_tags( $cFileContent) ;
for ($ns = 0 ; $ns < $nSearch; $ns ++)
{
// Debug
//echo "
Line $nZeile: " . htmlspecialchars ($cZeile) . "
\n";
// in PHP 4.0b3 and newer:
$pos = strpos (strtoupper($cFileContent), $aSearch[$ns]);
if ($pos === false)
{ // note: three equal signs
// not found... -> Naechste Datei ...
break ;
}
else
{
// Gefunden (Hurra)
if ($ns == $nSearch - 1)
{
// #### Ausgabe der gefundenen Datei-Infos ####
$cDate = strftime("%d.%m.%Y %H:%M:%S", filemtime($cFile)) ;
printf("
%s dated %s - %d Bytes",
$cFile, $cFile, $cDate, filesize($cFile)) ;
// Teil aus Datei entnehmen
$cZeile = substr($cFileContent, max(1, $pos - 50), 100 ) ;
// #### Ausgabe der Zeile ####
printf("
... %s ... ", $cZeile) ;
// Datei nicht weiter durchsuchen
$nFound++ ;
break ;
} // if ns == $nSearch - 1
} // if pos === false
} // for ns
} // if file != .
} // while readdir
closedir($hDir);
if ($nFound == 0)
printf("
Searched word %s NOT found - sorry", $SEARCH) ;
} // isset(search)
?>