打印本文 打印本文  关闭窗口 关闭窗口
搜索和替换文件或目录的一个好类--很实用
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 14:35:53
这是个非常有用的程序,可以对文本文件进行特定的搜索,并以特定的文字替换指定的文字,举个例子说如果我这篇文章里有一个字全部打错了,有几十处,要一一找出来修改是件很麻烦的事,用下面这个就可以轻松搞定。--teaman.oso.com.cn
类文件 search_replace.inc
<?php


        class search_replace{

                var $find;
                var $replace;
                var $files;
                var $directories;
                var $include_subdir;
                var $ignore_lines;
                var $ignore_sep;
                var $occurences;
                var $search_function;
                var $last_error;

        //以下进行函数定义和设置
         
                function search_replace($find, $replace, $files, $directories = ', $include_subdir = 1, $ignore_lines = array()){

                        $this->find            = $find;
                        $this->replace         = $replace;
                        $this->files           = $files;
                        $this->directories     = $directories;
                        $this->include_subdir  = $include_subdir;
                        $this->ignore_lines    = $ignore_lines;

                        $this->occurences      = 0;
                        $this->search_function = 'search';
                        $this->last_error      = ';

                }

        /***************************************
        ** Accessor for retrieving occurences.
        ***************************************/
                function get_num_occurences(){
                        return $this->occurences;
                }

        //获取最后的错误
                function get_last_error(){
                        return $this->last_error;
                }

        //设置FIND变量
                function set_find($find){
                        $this->find = $find;
                }

        //设置replace变量
                function set_replace($replace){
                        $this->replace = $replace;
                }

        //设置FILE变量
                function set_files($files){
                        $this->files = $files;
                }

        //设置目录变量
                function set_directories($directories){
                        $this->directories = $directories;
                }

        //设置目录变量 set_include_subdir
                function set_include_subdir($include_subdir){
                        $this->include_subdir = $include_subdir;
                }

        //设置ignore_lines变量
                function set_ignore_lines($ignore_lines){
                        $this->ignore_lines = $ignore_lines;
                }

        //确定是哪一种搜索方式
                function set_search_function($search_function){
                        switch($search_function){
                                case 'normal': $this->search_function = 'search';
                                               return TRUE;
                                               break;

                                case 'quick' : $this->search_function = 'quick_search';
                                               return TRUE;
                                               b

[1] [2] [3] [4]  下一页



打印本文 打印本文  关闭窗口 关闭窗口