网页功能: 加入收藏 设为首页 网站搜索  
全文搜索和替换
发表日期:2004-07-22作者:[转贴] 出处:  

<?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> ";  
}  
echo "OS Error: $errorCode<BR> ";  
echo "Check 'man errno' and count down<BR> ";  
echo "Usually paths/permissions<BR> ";  
}  
while (list(,$path) = each($results)){  
$parts = explode(':', $path);  
$path = $parts[0];  
$fp = fopen($path, 'r') or print("Cannot read $path<BR> ");  
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> ");  
if ($fp){  
fwrite($fp, $newdata);  
fclose($fp);  
echo $path, "<BR> ";  
}  
}  
}  
?>  
Example  
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir  

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 全文搜索和替换
本类热点文章
  用PHP验证邮箱是否真实有效
  PHP5的变化与PHP6展望
  用户IP、浏览器、操作系统
  oracle资料库函式库
  oracle资料库函式库
  基于PHP的聊天室(二)
  基于PHP的聊天室(二)
  php调用mysql存储过程和函数的方法
  正则表达式在网络编程中的运用
  专家预言:PHP将比Java更受欢迎
  高效的中文字符串截取函数
  高效的中文字符串截取函数
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.01136