PHP Classes

File: test_filter.php

Recommend this page to a friend!
  Classes of beiliwenxiao   Text Filter   test_filter.php   Download  
File: test_filter.php
Role: Class source
Content type: text/plain
Description: Example
Class: Text Filter
Search for a text string in a file
Author: By
Last change: Function into a class
Date: 15 years ago
Size: 1,233 bytes
 

Contents

Class file image Download
<?php
/*
*Author:beiliwenxiao
*Description:It's very simple,Just a test.Please do not laugh at me.
*/
class Filter
{
    public
$filename;
    public
$check_text;
    public
$check;
   
    function
setFileName($filename)
    {
       
$this->filename = $filename;
    }

    function
setCheckText($check_text)
    {
       
$this->check_text = $check_text;
    }

    function
getCheck()
    {
       
$fp=fopen($this->filename,"r");
       
$this->check=0;
        while (!
feof($fp))
        {
           
$filter=fgets($fp);
           
$filter=trim($filter);
            if(
stristr($this->check_text,$filter))
            {
               
$this->check=1;
                break ;
            }
        }
       
fclose($fp);
        return
$this->check;
    }

}

/*
*example
*/
$Filter= new Filter;
$Filter->setFileName('filter_test.txt');
$Filter->setCheckText('a');


echo
"IF you check_text in filter_test.txt <br />";
echo
"Like this:<br/>A<br/>ABC<br/>your words 1<br/>your words 2<br/>...<br/><br/>";
echo
"Search 'a' <br />";
echo
"It return:".$Filter->getCheck();
echo
"<br />";

$Filter->setCheckText('b');
echo
"Search 'b' <br />";
echo
"It return:".$Filter->getCheck();
echo
"<br/><br/>IF you Check_text have 'a' Like 'Action'. <br />";

$Filter->setCheckText('Action');

echo
"It return:".$Filter->getCheck();

?>