我想替换sql文件中的一些字符串。我已经编写了一个应该这样做的PHP脚本。但是,在我添加了while循环槽这个大文件(1.2GB)之后,替换功能不再适用了。
$reading = fopen('m.sql', 'r');
$writing = fopen('m.tmp', 'w');
$search = array("ä",
"Ä",
"ö",
"Ö",
"ü",
"Ü",
"€",
"§",
"ß",
"latin1_general_ci",
"CHARSET=latin1",
"‚",
"„",
"‘",
"’",
"“",
"â€",
"©",
"®");
$replace = array("ä",
"Ä",
"ö",
"Ö",
"ü",
"Ü",
"€",
"§",
"ß",
"utf8_general_ci",
"CHARSET=utf8",
"‚",
"„",
"‘",
"’",
"“",
"”",
"©",
"®");
if ($reading) {
// read one line or 4096 bytes, whichever comes first
while (($dateiinhalt = fgets($reading, 4096)) !== false) {
// replace in that and write to output file
fwrite($writing, str_replace($search, $replace, $dateiinhalt));
}
if (!feof($reading)) { // fgets() failed, but not at end of file
echo "Error: unexpected fgets() fail\n";
}
fclose($reading);
fclose($writing);
}
echo "done";
可能是什么问题?
答案 0 :(得分:0)
解决方案是将php版本从5.5更改为7