本文为大家讲解的是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
本文为大家讲解的是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";
}
}
}
?>
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!