html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

全文搜索和替换_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://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir  
TgBHTML5中文学习网 - HTML5先行者学习网
TgBHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助