note 38031 deleted from function.intval by vrana

From: Date: Tue, 15 Mar 2005 13:55:34 +0000
Subject: note 38031 deleted from function.intval by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-86474@lists.php.net to get a copy of this message
Note Submitter: till at klimpong dot com ---- 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. :-)

« previous php.notes (#86474) next »