【发布时间】:2016-10-05 03:39:06
【问题描述】:
我想替换 sql 文件中的一些字符串。我写了一个 php 脚本,应该这样做。但是在我添加了循环通过那个大文件(1.2GB)的while之后,替换不再起作用了。
$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";
可能是什么问题?
【问题讨论】:
-
好的,有什么解决办法?
-
不是直接通过现有工具转换编码的选项吗?在 linux 命令行上?
-
那会是什么?
-
现在我混合了 latin1 和 utf8(不是我的失败是这样的),我希望得到正确的 utf8 和所有特殊字符
-
有几种工具,您可以通过搜索引擎找到 - 其中之一:iconv - 另见stackoverflow.com/questions/11316986/…
标签: php