Home >Backend Development >PHP Tutorial >A simple way to implement text counter in PHP_php tips
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:
<?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); } ?>
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.