PHP新手,我将文本文件读入字符串变量,删除双引号并将内容写回文本文件。问题是文本文件在保存后只包含这样的垃圾:
^ @ 2 ^ @ 0 ^ @ 1 ^ @ 0 ^ @ - ^ @ 1 ^ @ 1 ^ @ - ^ @ 2 ^ @ 0 ^ @ ^ @ 1 ^ @ 3 ^ @:^ @ 5 ^ @ 5 ^ @, ^ @ ^ @ H ^ @ K ^ @ L ^ @ M 1 @ \ ^ @小号^ @ o ^ @ F的
我显然在这里做了一些非常错的事情..这是代码:
function replacequotes("myCommaSeparatedFile.csv")
{
$rfile = fopen($filename, "r") or die("Unable to open file!");
$outputfile = fopen("test2.csv", "w") or die("Unable to open file!");
$readtext = fread($rfile, filesize($filename));
$textoutput = str_replace('"', '', $readtext);
echo $textoutput; // <- this shows ok on screen
fwrite($outputfile, $textoutput);
fclose($inpufile);
fclose($outputfile);
}
请有人帮助我,谢谢。
问题解决了。 dos2unix
是一个有用的命令。再次感谢阿里代码清洁!