note 38031 added to function.intval

From: Date: Fri, 05 Dec 2003 12:28:21 +0000
Subject: note 38031 added to function.intval
Groups: php.notes 
Request: Send a blank email to php-notes+get-61444@lists.php.net to get a copy of this message
A lot of people use those file based counters in PHP where they write a certain value (e.g. number of hits a website recieved) to a file. On the next "hit", they read from the file and increment the value. (Not gonna argue the extreme sillyness of the method! :-)) If you don't upload your files in ASCII mode or whatever and if you are dealing with "the clueless" in general (for example, people manipulating the count and adding spaces by mistake at the end), intval() can save your butt. E.g.: <?php $count=file("count.txt"); $no=intval($count[0]); $no++; ?> Forces conversion of the string to an integer value, which you'll be able to increment. :-) ---- Manual Page -- http://www.php.net/manual/en/function.intval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38031 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38031&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38031&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61444) next »