Home > Backend Development > PHP Tutorial > A simple way to implement text counter in PHP_php tips

A simple way to implement text counter in PHP_php tips

WBOY
Release: 2016-05-16 19:53:31
Original
2550 people have browsed it

The example in this article describes how to simply implement a text counter in PHP. Share it with everyone for your reference, the details are as follows:

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

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP regular expression usage", "Summary of PHP ajax skills and applications", " Summary of PHP operations and operator usage", "Summary of PHP network programming skills", "PHP basic syntax introductory tutorial", "PHP operation office Summary of document skills (including word, excel, access, ppt) ", "Summary of PHP date and time usage ", "PHP object-oriented programming introductory tutorial ", " Summary of php string (string) usage", "Introduction to php mysql database operation tutorial" and "Summary of common php database operation skills"

I hope this article will be helpful to everyone in PHP programming.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template