手机
当前位置:查字典教程网 >编程开发 >php教程 >全文搜索和替换
全文搜索和替换
摘要:Examplehttp://yourserver.com/globalreplace.php?oldword=test&newword=te...

<?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

【全文搜索和替换】相关文章:

PHP查找与搜索数组元素方法总结

php实现CSV文件导入和导出方法

基于文本的访客签到簿

php函数重载的替代方法

做个自己站内搜索引擎

Php部分常见问题总结第1/2页

PHP文本数据库的搜索方法

文章推荐系统(二)

基于文本的搜索

php微信公众平台开发类实例

精品推荐
分类导航