繁体   English   中英

PHP基本写入错误,未获得任何结果

[英]PHP basic write error, not getting any result

只是想知道这里出了什么问题,为此已经花了我太长时间了。 这是一个由另一个php脚本调用的脚本,它可以正常工作,直到应该向文件写入0.0的最后一位为止。 -1和1都写入文件,但不写入0.0 我不知道我在做什么错。 输出文件只是空白。 我禁用了最后一位,我完美地看到了-1和1 ,但是当我启用0部分时,他的文件中没有任何内容。

这些值也是整数还是字符? 我问这是因为另一个程序将要读取newfile.txt并取出数据。

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

if ($_POST['leftb'])
{ echo "Left is pressed";
    $txt = "-1 \n";}


else if ($_POST['rightb'])
{ echo "Right is pressed";
    $txt = "1 \n";}


fwrite($myfile, $txt);                                              // Write either -1 or 1 to the file
fclose($myfile);                                                    // Close the file



sleep(2);
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); // Open It again
$txt = "0.0 \n";
write($myfile, $txt);                                              // Write 0 to the file

fclose($myfile);

?>

你有错

像这样改变。 写($ myfile,$ txt)=> fwrite($ myfile,$ txt)

一切正常。

在代码开头

添加两行。

使用error_reporting(E_ALL);

ini_set(“ display_errors”,1);

这将告诉您出了什么问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM