找不到工具就自己寫, 反正沒幾行
自己把開頭的 $search 與 $replace 改成你要搜尋與取代的文字
<pre class="c" name="code">
<?php
$search = "xxxxx";
$replace = "oooooo";
function usage_exit() {
echo "Usage {$argv[0]} <zip file>\n";
exit(1);
}
if ($argc != 2 || !file_exists($argv[1])) {
usage_exit();
}
$zip = new ZipArchive();
$ret = $zip->open($argv[1]);
if (true !== $ret) {
echo "failed to open zip file\n";
exit(1);
}
$fileNum = $zip->numFiles;
for($i = 0; $i < $fileNum; ++$i){
$stat = $zip->statIndex($i);
$name = $stat['name'];
echo "$i processing {$name}\n";
if (!preg_match('/\.txt$/', $name)) {
continue;
}
$content = $zip->getFromName($name);
$new_data = str_replace($search, $replace, $content);
$zip->deleteName($name);
$zip->addFromString($name, $new_data);
}
$zip->close();
用法:
一次一個, 記得 zip 檔要備份, 我不保證這程式不會弄壞啥