exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);
if ($errorCode){
if ($errorCode == 1) {
echo "可能找不到包含$oldword 的檔案
n";
}
echo "作業系統錯誤:$errorCode
n";
echo "檢查'man errno"檢查'man errno"檢查'man errno "檢查'man errnono "檢查'man errno"檢查'man errno"檢查'man errno)。 '且倒數
n";
echo "通常是路徑/權限
n";
}
while (list(,$path) = every($results)){
$parts =explode(':', $path);
$path = $parts[0];
$fp = fopen($path, 'r') 或print("無法讀取$path
n");
if ($fp){
$data = fread($fp, filesize($path));
fclose($fp);
$newdata = str_replacenew ($oldword, $newword, $data);
$fp = fopen($path, 'w') 或print("無法寫入$path
n");
if ($fp) {
fwrite($fp, $newdata);
fclose($fp);
echo $path, "
n"; } >? >
範例
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir
http://www.bkjia.com/PHPjc/315906.html
www.bkjia.com