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

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

WBOY
Release: 2018-10-25 16:41:55
Original
1945 people have browsed it

这篇文章主要介绍了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);
  }
?>
Copy after login

【相关教程推荐】

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

2. php从入门到精通  

3. bootstrap教程 

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template