note 42400 added to function.strpos

From: Date: Fri, 14 May 2004 20:23:41 +0000
Subject: note 42400 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-69620@lists.php.net to get a copy of this message
//I needed a script to find a specific var in a textfile (in this case the date), then put it into a string //The file is formatted this way : todays_date="00.00.00" something here. //With this script, the todays_date can be anywhere in the file and it will still work. The script checks if the datestamp in the file is todays, or else it archives the file. //You will have to edit +13 and +8 to your needings. In this case, the thirtheenth character after the initial T is the first 0, and the last 0 is 8 characters after the first 0.(this number is equivalent to the length of the string you want to get from the file) <?php $today = date("m.d.y"); $file="file.txt"; $string=file_get_contents($file); $tocount=strpos($string, 'todays_date="') + 13; $endof=$tocount+8; $newstring=""; for($i=$tocount; $i<$endof; $i++){ $newstring=$newstring.$string[$i]; } echo $newstring; if($newstring!==$today){ //place the info in a new document in format : m.d.y_arc.txt $archive=$newstring."_arc.txt"; $handle = fopen($archive, "w+"); fwrite($handle, $string); fclose($handle); //delete everything in $file, w+ truncates the files length to 0 $handle = fopen($file, "w+"); fclose($handle); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42400 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42400&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42400&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69620) next »