note 49440 added to function.strlen

From: Date: Thu, 27 Jan 2005 23:32:13 +0000
Subject: note 49440 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-84096@lists.php.net to get a copy of this message
Note on the FilePop. It should be modified stlightly so as not to throw a warning: function FilePop($filename, $terminator="\n") { if (file_exists($filename)) { $oldStuff = file_get_contents($filename); //get those file contents $pos = strpos($oldStuff, $terminator); // find our first terminator if ($pos == false) { //No terminator detected. Is there one item or no items? if (strlen($oldStuff) < 1) { // There is nothing! $result = false; } else { //There is only one thing! $result = $oldStuff; //store that thing file_put_contents ( $filename, ''); //pop it out of file } } else { //There are many things, and we found the first one $result = substr($oldStuff, 0, $pos); //get the first thing file_put_contents ( $filename, substr($oldStuff, ($pos + strlen($terminator))) ); //re-put everything but the popped item in the file. } } else { $result = false; } return $result; //return whatever happened } ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49440 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49440&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49440&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49440&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49440&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49440&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49440&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84096) next »