php全文搜索和替换

时间:2010-01-08 08:24:37   来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: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 = fo...
  正文:

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


来源:http://www.002pc.com/master/College/Programming/PHP/11615.html

收藏到:

关于《php全文搜索和替换》文章的评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

随机文章

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by rand() limit 10

顶出来的热门

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by diggtop desc,id desc limit 10
站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td