PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bao Nguyen Quoc  >  String Searcher  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Example
Class: String Searcher
Search for text in files of any size
Author: By
Last change: Fix example :D
Date: 9 years ago
Size: 1,310 bytes
 

Contents

Class file image Download
<?
$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();
}
?>