⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replace.php

📁 BBWPS 宾馆管理系统 php+mysql
💻 PHP
字号:
<?/*    [BBWPS!] (C)2006-2010 小蜜蜂版权所有.	This is NOT a freeware, use is subject to license terms*/class ReplaceFile{	var $msg="";	var $sub;	var $backPath;	var $arrFileType;	var $arrSearch;	var $arrReplace;	var $intCount;	var $isReg;	var $subfolder;	var $repNum=0;	var $allowBack;	function ReplaceFile($arrConfig){		$this->sub            = $arrConfig['sub'];		$this->isReg          = $arrConfig['isReg'];		$this->subfolder      = $arrConfig['subfolder'];		$this->strReplacePath	= $arrConfig['replacePath'];		$this->arrFileType		= $arrConfig['fileType'];		$this->arrSearch		  = $arrConfig['search'];		$this->arrReplace		  = $arrConfig['replace'];		$this->intCount			  = 0;				if ($this->checkConfig()){			$startTime = time();			$this->flushStatus('start');			$this->getFilePath($this->strReplacePath);			$time = date('H小时i分s秒', mktime(0, 0, (time()-$startTime)));			$note = "替换结束,";			$note.="共替换".$this->repNum."处,";			$note.="共替换文件".$this->intCount."个,耗时".$time."</font>";			$this->flushStatus($note);		}			echo $this->msg;	}		function checkConfig(){		if (!is_array($this->arrFileType) || !is_array($this->arrSearch) || !is_array($this->arrReplace)){			return false;		}		return true;	}				function getFilePath($path){		if (is_dir($path)){			$arrDir = scandir($path);			foreach ($arrDir as $file){				if (is_dir($path.$file)){					if($this->sub){						if ($file != "." && $file != ".."){							$this->getFilePath($path.$file.'/');						}					}				}				else{					$path_parts = pathinfo($path.$file);					if (array_search($path_parts['extension'], $this->arrFileType) !== false){						if(!$this->rewriteFile($path.$file)){							$this->flushStatus('error'.$file);						}					}				}			}		}	}		function rewriteFile($filePath){		$fileContent = file_get_contents($filePath);		foreach ($this->arrSearch as $key=> $search){			if(!$this->isReg){				$fileContent = str_replace($search, $this->arrReplace[$key], $fileContent,$count);			}			else{			  $count=preg_match_all("/".$search."/",$fileContent,$tmp);				$fileContent = preg_replace("/".$search."/", $this->arrReplace[$key], $fileContent);			}			if($count>0){										$this->intCount++;				$this->flushStatus($filePath." 替换个数:".$count."个<br />");			}			$this->repNum+=$count;		}				if (!$handle = @fopen($filePath, 'w')){			return false;		}		if (@fwrite($handle, $fileContent) === false){			fclose($handle);			return false;		}		fclose($handle);		return true;	}		function flushStatus($status){		if ($status == 'start'){				$this->msg.="<font color=#FFFFFF>文件正在替换...... <br />替换目录:".$this->strReplacePath."<br />正则: ".($this->isReg?"是":"否")."<br />文件类型:".@implode('、', $this->arrFileType)."<br />";				foreach ($this->arrSearch as $key=>$search){					$this->msg.=$search.' 替换为 '.$this->arrReplace[$key]."<br />";				}				$this->msg.="开始替换<br />";		}		else{			$this->msg.=$status;		}		flush();	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -