加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

全文搜索和替换

发布时间:2020-03-21 09:49:53 所属栏目:PHP教程 来源:互联网
导读:全文搜索和替换
<?php  
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);  
if ($errorCode){  
if ($errorCode == 1){  
echo "Possibly no files were found with $oldword in them<BR>n";  
}  
echo "OS Error: $errorCode<BR>n";  
echo "Check 'man errno' and count down<BR>n";  
echo "Usually paths/permissions<BR>n";  
}  
while (list(,$path) = each($results)){  
$parts = explode(':', $path);  
$path = $parts[0];  
$fp = fopen($path, 'r') or print("Cannot read $path<BR>n");  
if ($fp){  
$data = fread($fp, filesize($path));  
fclose($fp);  
$newdata = str_replace($oldword, $newword, $data);  
$fp = fopen($path, 'w') or print("Cannot write $path<BR>n");  
if ($fp){  
fwrite($fp, $newdata);  
fclose($fp);  
echo $path, "<BR>n";  
}  
}  
}  
?>  
Example  
?oldword=test&newword=text&rootpath=http://www.jb51.net/path/to/dir  

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读