Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将以前的数据保存在文本文件中?_Php_Html - Fatal编程技术网

Php 如何将以前的数据保存在文本文件中?

Php 如何将以前的数据保存在文本文件中?,php,html,Php,Html,因此,基本上,我有一个表单,在提交时打开一个php文件,我有php写入文件,但它不会继续添加值,文本文件只有一个“1”,而每次提交表单时它应该有一个“1”。这是我的密码 <?php $myFile = "Data.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "1"; fwrite($fh, $stringData); fclose($fh); ?> 如Robert Rozas所述,

因此,基本上,我有一个表单,在提交时打开一个php文件,我有php写入文件,但它不会继续添加值,文本文件只有一个“1”,而每次提交表单时它应该有一个“1”。这是我的密码

<?php
$myFile = "Data.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "1";
fwrite($fh, $stringData);
fclose($fh);
?>

如Robert Rozas所述,以仅附加的格式打开:
fopen($myFile,'a+')

或者获取内容并手动附加一些伪[esk]-代码:

$contents = file_get_contents("somefile.txt");
//generate what to write
$contents .= $whatIGenerated;
$success = file_put_contents("somefile.txt", $contents);

如Robert Rozas所述,以仅附加的格式打开:
fopen($myFile,'a+')

或者获取内容并手动附加一些伪[esk]-代码:

$contents = file_get_contents("somefile.txt");
//generate what to write
$contents .= $whatIGenerated;
$success = file_put_contents("somefile.txt", $contents);

如Robert Rozas所述,以仅附加的格式打开:
fopen($myFile,'a+')

或者获取内容并手动附加一些伪[esk]-代码:

$contents = file_get_contents("somefile.txt");
//generate what to write
$contents .= $whatIGenerated;
$success = file_put_contents("somefile.txt", $contents);

如Robert Rozas所述,以仅附加的格式打开:
fopen($myFile,'a+')

或者获取内容并手动附加一些伪[esk]-代码:

$contents = file_get_contents("somefile.txt");
//generate what to write
$contents .= $whatIGenerated;
$success = file_put_contents("somefile.txt", $contents);

将这一行更改为:

$fh = fopen($myFile, 'a') or die("can't open file");

使用
w
表示写入,使用
a
表示追加。

将这一行更改为:

$fh = fopen($myFile, 'a') or die("can't open file");

使用
w
表示写入,使用
a
表示追加。

将这一行更改为:

$fh = fopen($myFile, 'a') or die("can't open file");

使用
w
表示写入,使用
a
表示追加。

将这一行更改为:

$fh = fopen($myFile, 'a') or die("can't open file");

使用
w
表示写入,使用
a
表示追加。

fopen($myFile,'a+')????您必须告诉我们更多有关要存储在文件中的数据的信息!fopen($myFile,'a+')????您必须告诉我们更多有关要存储在文件中的数据的信息!fopen($myFile,'a+')????您必须告诉我们更多有关要存储在文件中的数据的信息!fopen($myFile,'a+')????您必须告诉我们更多有关要存储在文件中的数据的信息!