手机
当前位置:查字典教程网 >编程开发 >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对象和数组相互转换的方法

基于文本的访客签到簿

PHP教程:PHP脚本编程中的文件系统函数库

新浪新闻小偷

基于文本的搜索

PHP获取数组的键与值方法小结

php中get_defined_constants函数用法实例分析

精品推荐
分类导航