全文搜索和替换

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

全文搜索和替换

  2021-03-16 我要评论
想了解全文搜索和替换的相关内容吗,在本文为您仔细讲解的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:|全文|文搜|搜索|索和|和替|替换|换|,下面大家一起来学习吧。
<?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://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir  

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们