您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
搜索和替换文件或目录的一个好类--很实用
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:35:53
;   //ereg搜索方法也不支持ignore_lines
                function ereg_search($filename){

                        clearstatcache();

                        $file = fread($fp = fopen($filename, 'r'), filesize($filename)); fclose($fp);

                        $occurences = count($matches = split($this->find, $file)) -1;
                        $file       = ereg_replace($this->find, $this->replace, $file);

                        if($occurences > 0) $return = array($occurences, $file); else $return = FALSE;
                        return $return;

                }

        //写新文件
                function writeout($filename, $contents){

                        if($fp = @fopen($filename, 'w')){
                                fwrite($fp, $contents);
                                fclose($fp);
                        }else{
                                $this->last_error = 'Could not open file: '.$filename;
                        }

                }

        //由do_search调用,排出所有要搜索的文件
                function do_files($ser_func){
                        if(!is_array($this->files)) $this->files = explode(',', $this->files);
                        for($i=0; $i<count($this->files); $i++){
                                if($this->files[$i] == '.' OR $this->files[$i] == '..') continue;
                                if(is_dir($this->files[$i]) == TRUE) continue;
                                $newfile = $this->$ser_func($this->files[$i]);
                                if(is_array($newfile) == TRUE){
                                        $this->writeout($this->files[$i], $newfile[1]);
                                        $this->occurences += $newfile[0];
                                }
                        }
                }

        //由do_search()调用,排出所有要搜索的目录
                function do_directories($ser_func){
                        if(!is_array($this->directories)) $this->directories = explode(',', $this->directories);
                        for($i=0; $i<count($this->directories); $i++){
                                $dh = opendir($this->directories[$i]);
                                while($file = readdir($dh)){
                                        if($file == '.' OR $file == '..') continue;

                                        if(is_dir($this->directories[$i].$file) == TRUE){
                                                if($this->include_subdir == 1){
                                                        $this->directories[] = $this->directories[$i].$file.'/';
                                                        continue;
                                                }else{
                                                        continue;
                                                }
                                        }

                                        $newfile = $this->$ser_func($this->directories[$i].$file);
&nb

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


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