php 全文搜索和替换的实现代码
作者:bea
<?php exec("/bin/grep-r'$oldword'$rootpath",$results,$errorCode); if($errorCode){ if($errorCode==1){ echo"Possiblynofileswerefoundwith?$oldwordinthem<BR>"; } echo"OSError:$errorCode<BR>"; echo"Check'manerrno'andcountdown<B
<?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>
";
}
}
}
?>
有用 | 无用
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>
";
}
}
}
?>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- PHP获取网站域名和地址的代码
- php-5.2下php.ini 中文版配置说明
- 继续收藏一些PHP常用函数
- php IIS日志分析搜索引擎爬虫记录程序
- php二分法在IP地址查询中的应用
- PHP调用MySQL的存储过程的实现代码
- 推荐学习php sesson的朋友必看PHP会话(Session)使用入门
- php多数据库支持的应用程序设计
- PHP+MYSQL 出现乱码的解决方法
- php自动适应范围的分页代码
- 用PHP读取RSS feed的代码
- IStream与TStream之间的相互转换
- 特详细的PHPMYADMIN简明安装教程
- phpmyadmin的安装与使用图文教程
- php-accelerator网站加速PHP缓冲的方法
- 新安装的MySQL数据库需要注意的安全知识
- MySql中正则表达式的使用方法描述
- php自动跳转中英文页面
- PHP一些常用的正则表达式字符的一些转换