EingabeFeld für SuchBegriffe


<html><head><title>Anzeige</title></head> <body bgcolor="#eeeeee"> <h2>EingabeFeld für SuchBegriffe</h2> <table border=0><tr> <form action="<? echo $PHP_SELF ?>" method="post"> <td><input type="text" name="formInput" len="30" maxlen="30" value="<? echo isset($formInput) ? htmlentities($formInput) : 'Such PHP Array' ?>"></td> <td><input type="submit" name="Submit"></td> </form> </tr></table><hr noshade size="1"> <? // ====================== HilfsFunktionen ================= // // Rekursives Einlesen von Dateien u. Verzeichnissen // Input : Array mit Basis-Directory // Return: Array mit allen File/Dir's in Unterverzeichnissen function GetAllFiles($arrDir) { $arrRet_F = array(); for($i=0; $i < count($arrDir); $i++ ) { $arr = $arrDir[$i]; $arrTmp_F = GetDirFiles($arr["Verz"].$arr["Name"]."/","File"); $arrRet_F = php3_array_merge($arrRet_F,$arrTmp_F); $arrTmp_D = GetDirFiles($arr["Verz"].$arr["Name"]."/","Dir"); $arrRet_F = php3_array_merge($arrRet_F, GetAllFiles($arrTmp_D) ); } return $arrRet_F; } // Files o. Dirs Einlesen; Link auf HTML-Datei // Return: Array; $mode = {"Dir","File"} function GetDirFiles($strPath,$mode) { $objDir = opendir($strPath); // Verzeichnis Oeffnen (Referenz) $arrDir = array(); while ($strFile = readdir($objDir)) { // Verzeichnis Einlesen if ( ((! strcmp($mode,"Dir") ) && is_dir($strPath.$strFile) ) || ((! strcmp($mode,"File")) && (! is_dir($strPath.$strFile) ) ) ) if ( IsSelectedFile($strFile,$mode) ) { $arrTags = array(); if ( ! is_dir($strPath.$strFile) ) $arrTags = GetDateiTags($strPath.$strFile); $tags_inhalt = $arrTags[0]; $tags = $inhalt = ""; for($i=0;$i<count($arrTags); $i++) { $tags_inhalt = $arrTags[$i]; if ( ! strstr($tags,$tags_inhalt[0]) ) $tags .= $tags_inhalt[0]." "; $inhalt .= $tags_inhalt[1]."|"; } $arrDir[] = array("Verz" => $strPath, "Name" => $strFile, "Link" => ereg(".htm",$strFile) ? "<A href=\"".$strPath.$strFile."\" target=\"_\">Link</A>" : "--", "Tref" => 0, "TAnz" => count($arrTags), "Tags" => $tags, "Inhalt" => $inhalt); } } closedir($objDir); // Verzeichnis Schließen return $arrDir; } // FilterFktion: welche File/Dir ausselektieren ? function IsSelectedFile($strFile,$mode) { if ( ! strcmp($mode,"Dir") ) { // a. Directory if ( ereg("^\.",$strFile) ) // nicht: "." ".." return false; } else { // b. Filter WEG-Mit wenn: if ( ! ereg("\.php3",$strFile) ) return false; // nicht ".php3" if ( ereg("\.inc" ,$strFile) ) return false; // wenn: ".inc" } return true; // OK: selektiert } // SuchMuster-Check in globalem DateiArray function SearchPattern($formInput) { global $arrResult; $arrWords = GetSearchWords($formInput); // Input in Words aufsplitten for($i=0;$i<count($arrResult);$i++) { $zaehler = 0; for($j=0;$j<count($arrWords);$j++) if ( eregi($arrWords[$j],$arrResult[$i]["Inhalt"]) ) $zaehler++; $arrResult[$i]["Tref"] = $zaehler; for($j=0;$j<count($arrWords);$j++) { $replace = "<font color=\"#ff0000\">".$arrWords[$j]."</font>"; $arrResult[$i]["Inhalt"] = str_replace($arrWords[$j],$replace,$arrResult[$i]["Inhalt"]); } } } // SuchWoerter aus Formular extrahieren function GetSearchWords($formInput) { $arrRet = array(); $arr = split(" ",trim($formInput)); // a. Aufsplitten in Words for($i=0;$i<count($arr);$i++) { if ( strlen($arr[$i]) > 1 ) // b. Word-Länge > 1 $arrRet[] = htmlentities($arr[$i]); // c. HTML-Sonderzeichen } for($i=0;$i<count($arrRet);$i++) echo "<b> $i:</b>_". $arrRet[$i] ."_ "; //echo "$i: _".htmlspecialchars($arrRet[$i])."_<br>\n"; echo "<p>\n"; return $arrRet; } // Ausgabe eines 2-dim-Assoz-Arrays als HTML-Tabelle function ShowArrayTable($arr) { $showheader = true; // Merker: Header schon ausgegeben ? $arr = php3_array_multisort($arr); // Sortierung echo "<TABLE cellpadding=\"3\" BORDER=1>"; for($i=0; $i < count($arr); $i++) { // alle Dateien/Verzeichnisse $arrDatei = $arr[$i]; if ( $showheader ) { // Table-Header (beim 1. Mal) $showheader = false; // dann verriegeln echo "<TR bgcolor=\"#cccccc\"><TH align=\"left\">"; echo implode("</TH><TH align=\"left\">\n",php3_array_keys($arrDatei)); echo "</TH></TR>"; } // Table-Data echo "<TR><TD>".implode("</TD><TD>\n",$arrDatei)."</TD></TR>"; } echo "</TABLE>"; } // Extrahiert Tags und TagInhalt aus HTML-Datei; // Return: Array; [0]-Tags (B,H1-x) [1]-Inhalt function GetDateiTags ($datei) { return GetHtmlTags("h1|H1|h2|H2|h3|H3", GetDateiStr($datei)); } // Extrahiert Html-Tags aus HtmlString // Return: 2-Dim-Array; [0]-Tag [1]-Inhalt function GetHtmlTags($tags,$htmlString) { $regExp = "<(".$tags.")>"; $arrRet = array(); $arr = split($regExp, $htmlString); for($i=1;$i < count($arr); $i++) { if ( ereg("([^<]+)</([^>]+)>",$arr[$i],$regs) ) $arrRet[] = array("$regs[2]","$regs[1]"); } return $arrRet; } // Liefert DateiInhalt als ein String zurück function GetDateiStr($dateiName) { if ( file_exists($dateiName) ) return implode("",file($dateiName)); return ""; } // ====================== ProgrammAblauf ================== // $rootPath = "../"; // BasisPfad // a. Alle Dateien rekursiv in ein Array einlesen $arrDir_D = GetDirFiles($rootPath,"Dir"); // Basis-Dir $arrDir_F1 = GetDirFiles($rootPath,"File"); // Basis-Files $arrDir_F2 = GetAllFiles($arrDir_D); // Files aus UnterVerzeichnisse $arrResult = php3_array_merge($arrDir_F1,$arrDir_F2); // Merge: alle in ein Array // b. SuchBegriffe analysieren if ( isset($formInput) ) { echo "\n<b>Eingabe:</b>_"; echo htmlentities($formInput)."_<br><b>Teil&nbsp;&nbsp;</b>"; SearchPattern($formInput); // Suche u. Eintrag in Array } // c. Ausgabe als HTML-Tabellen ShowArrayTable($arrResult) ; // Ergebnis als Tabelle anzeigen ?> </body></html>