Home >php教程 >php手册 >PHP如何制作简单的文本计数器(附代码)

PHP如何制作简单的文本计数器(附代码)

WBOY
WBOYOriginal
2016-06-13 09:39:321931browse

这篇文章主要介绍了PHP简单实现文本计数器的方法,涉及PHP针对文本文件的简单判断,读取及写入等操作技巧,需要的朋友可以参考下

<?php
  if (file_exists(&#39;count_file.txt&#39;))
  {
    $fil = fopen(&#39;count_file.txt&#39;, r);
    $dat = fread($fil, filesize(&#39;count_file.txt&#39;));
    echo $dat+1;
    fclose($fil);
    $fil = fopen(&#39;count_file.txt&#39;, w);
    fwrite($fil, $dat+1);
  }
  else
  {
    $fil = fopen(&#39;count_file.txt&#39;, w);
    fwrite($fil, 1);
    echo &#39;1&#39;;
    fclose($fil);
  }
?>

【相关教程推荐】

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn