欢迎光临第一亲子网
您当前位置: 第一亲子网 > 儿童发育 > 全文搜索和替换 > 正文

全文搜索和替换

2013-9-3 | 来源:第一亲子网 | 点击:

导读: 牋 Example牋 http://yourserver.com/globalreplace.PHP?oldword=test&newword=text&rootpath=/path/to/dir牋 ...

PHP牋
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);牋
if ($errorCode){牋
if ($errorCode == 1){牋
echo "Possibly no files were found with $oldword in them
";牋
}牋
echo "OS Error: $errorCode
";牋
echo "Check 'man errno' and count down
";牋
echo "Usually paths/permissions
";牋
}牋
while (list(,$path) = each($results)){牋
$parts = explode(':', $path);牋
$path = $parts[0];牋
$fp = fopen($path, 'r') or print("Cannot read $path
");牋
if ($fp){牋
$data = fread($fp, filesize($path));牋
fclose($fp);牋
$newdata = str_replace($oldword, $newword, $data);牋
$fp = fopen($path, 'w') or print("Cannot write $path
");牋
if ($fp){牋
fwrite($fp, $newdata);牋
fclose($fp);牋
echo $path, "
";牋
}牋
}牋
}牋
?>牋
Example牋
http://yourserver.com/globalreplace.PHP?oldword=test&newword=text&rootpath=/path/to/dir牋

上一篇:一个用于mysql的数据库抽象层函数

下一篇:PHP4与PHP3中一个不兼容问题的解