note 49440 deleted from function.strlen by dave

From: Date: Fri, 05 May 2006 03:28:32 +0000
Subject: note 49440 deleted from function.strlen by dave
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-110605@lists.php.net to get a copy of this message
Note Submitter: corey at eyewantmedia dot com ---- 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 }

« previous php.notes (#110605) next »