PHP在文本文件中递增计数变量 [英] PHP Increment a counting variable in a text file
本文介绍了PHP在文本文件中递增计数变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这看起来很简单,但我无法弄清楚.
This seems simple but I can't figure it out.
file_get_contents('count.txt');
$variable_from_file++;
file_put_contents('count.txt', $variable_from_file);
count.txt
中只有一行数据,它是命中计数器.有办法吗?
There is only one line of data in count.txt
and it is the hits counter. Is there a way to do this?
推荐答案
$variable_from_file = (int)file_get_contents('count.txt');
但是请注意,这不是线程安全的.
But notice that this is not thread-safe.
这篇关于PHP在文本文件中递增计数变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文