file_put_contents在php中自动增加重复的int值?

时间:2017-03-27 21:23:06

标签: php file-put-contents

我的代码很小。

total_request.txt是文本文件,内容值= 1

$file = 'total_request.txt';
$count = file_get_contents( $file );
echo $a = $count + 1;  
file_put_contents( $file, $a ); 

代码输出值:2

但是文件total_request.txt有内容3.我想在运行这个文件时自动增加1。

我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

您可能希望以附加模式打开文件:

<?php
$fp = fopen('data.txt', 'a');//opens file in append mode  
fwrite($fp, ' this is additional text ');  
fwrite($fp, 'appending data');  
fclose($fp);
?>

希望对您有帮助。

致谢。

相关问题