SearchResult::SearchText PHP Method

SearchText() public method

public SearchText ( $phrase, $case )
    function SearchText($phrase = 0, $case = 0)
    {
        $qq = @explode(' ', $this->text);
        $delim = '|';
        if ($phrase) {
            foreach ($qq as $k => $v) {
                $qq[$k] = '\\b' . $v . '\\b';
            }
        }
        $words = '(' . @implode($delim, $qq) . ')';
        $pattern = "/" . $words . "/";
        if (!$case) {
            $pattern .= 'i';
        }
        foreach ($this->FilesToSearch as $k => $filename) {
            $this->FileMatchesCount[$filename] = 0;
            $FileStrings = @file($filename) or @next;
            for ($a = 0; $a < @count($FileStrings); $a++) {
                $count = 0;
                $CurString = $FileStrings[$a];
                $CurString = @Trim($CurString);
                $CurString = @strip_tags($CurString);
                $aa = '';
                if ($count = @preg_match_all($pattern, $CurString, $aa)) {
                    $CurString = @preg_replace($pattern, "<SPAN style='color: #990000;'><b>\\1</b></SPAN>", $CurString);
                    $this->ResultFiles[$filename][$a + 1] = $CurString;
                    $this->MatchesCount += $count;
                    $this->FileMatchesCount[$filename] += $count;
                }
            }
        }
        $this->TimeTotal = @round(getmicrotime() - $this->TimeStart, 4);
    }

Usage Example

Beispiel #1
0
    } else {
        if (@eregi("^win", $os)) {
            $windows = 1;
        } else {
            $unix = 1;
        }
    }
}
if (!empty($_POST['s_dir']) && !empty($_POST['s_text']) && !empty($_POST['cmd']) && $_POST['cmd'] == "search_text") {
    echo $head;
    if (!empty($_POST['s_mask']) && !empty($_POST['m'])) {
        $sr = new SearchResult($_POST['s_dir'], $_POST['s_text'], $_POST['s_mask']);
    } else {
        $sr = new SearchResult($_POST['s_dir'], $_POST['s_text']);
    }
    $sr->SearchText(0, 0);
    $res = $sr->GetResultFiles();
    $found = $sr->GetMatchesCount();
    $titles = $sr->GetTitles();
    $r = "";
    if ($found > 0) {
        $r .= "<TABLE width=100%>";
        foreach ($res as $file => $v) {
            $r .= "<TR>";
            $r .= "<TD colspan=2><font face=Verdana size=-2><b>" . ws(3);
            $r .= $windows ? str_replace("/", "\\", $file) : $file;
            $r .= "</b></font></ TD>";
            $r .= "</TR>";
            foreach ($v as $a => $b) {
                $r .= "<TR>";
                $r .= "<TD align=center><B><font face=Verdana size=-2>" . $a . "</font></B></TD>";