【发布时间】:2015-05-27 03:54:09
【问题描述】:
我正在尝试将页面浏览量保存在 txt 文件中。所以当页面被访问时,脚本会更新txt文件,数字会增加+1。
我的page_views.txt 文件包含以下内容:
[page_views]
[page_views] 是页面浏览次数,例如:[500],每次访问页面时都会更新。
save_hits.php
<?Php
$f=file("p.txt");
$getc=$f[0];
$addition=$getc. '+1';
$f_ope=fopen("p.txt","w");
fputs($f_ope,$addition);
fclose($f_ope);
?>
page_hits.php
<?Php
$x=file("p.txt");
echo "+$x[0] views";?>
但问题是它没有按预期工作,
每当page_hits.php 脚本运行时,我都会得到结果:
1+1+1+1 views
预期的输出应该在哪里:
4 views
而且每次命中应该增加 +1。
你知道如何解决它吗?
【问题讨论】: