<?
 
$filename = stripslashes(@$_POST['filename']);
 
$search = stripslashes(@$_POST['search']);
 
$case = (bool)@$_POST['case'];
 
?>
 
<form action="test.php" method=post>
 
Filename : <input type=text value="<?=htmlspecialchars($filename)?>" name="filename"><br>
 
Search for : <input type=text value="<?=htmlspecialchars($search)?>" name="search"> <input <?=($case ? "checked" : "")?> name=case type=checkbox value="1"> Matchcase<br>
 
<input type=submit value=Search>
 
</form>
 
<?
 
 
function microtime_float()
 
{
 
   list($usec, $sec) = explode(" ", microtime());
 
   return ((float)$usec + (float)$sec);
 
}
 
 
require_once("stringsearcher.php");
 
 
if ($filename && $search)
 
{
 
    
 
    $f = new StringSearcher();
 
    
 
    $time = microtime_float();
 
    
 
    $f->search = $search;
 
    $f->matchcase = $case;
 
    
 
    if (!$f->open($filename))
 
    {
 
        echo "File not found : <b>$filename</b><br><br>\n";
 
    }
 
    else
 
    {
 
        echo "Search for <b>$search</b> in <b>$filename</b><br><br>\n";
 
    }
 
    
 
    $old = -1;
 
    
 
    $total = 0;
 
    
 
    while ($f->search())
 
    {    
 
        if ($f->found != -1)
 
        {
 
            echo "Found <b>$search</b> at position " . $f->found . "<BR>\n";
 
            $total++;
 
        }
 
        flush();
 
    }
 
    
 
    echo "Search finished<br>\n";
 
    echo "$total found  in " . round((microtime_float() - $time) , 3) . " second<br>";
 
    
 
    $f->close();
 
}
 
?>
 
 |