0
PHP新手,即時消息將文本文件讀入字符串變量,刪除雙引號並將內容寫回文本文件。問題是,保存後的文本文件,只是包含這樣的垃圾:PHP - 無法將字符串變量保存爲文本文件,損壞
^@ 2^@ 0^@ 1^@ 0^@ -^@ 1^@ 1^@ -^@ 2^@ 0^@ ^ @ 1^@ 3^@:^ @ 5^@ 5^@,^ @^@ H^@ K^@ L^@ M^@^^ S^@ 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);
}
有人可以幫我請,謝謝。
[PHP創建並保存到根目錄的txt文件]的可能副本(https://stackoverflow.com/questions/9265274/php-create-and-save-a-txt-file-to-root-directory ) – Star
你發佈的「垃圾」根本不是垃圾。它是以UTF-16BE編碼的文本。在記事本中打開它,並呈現正確。 – axiac