I want to replace some strings in a sql file. I've written a php script that should do that. But after I added the while for looping trough that big file (1.2GB) the replacing is not working anymore.
$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";
What could be the problem?