您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
搜索和替换文件或目录的一个好类--很实用
作者:采集员 文章来源:来源于网络 点击数: 更新时间: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] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |