note 42400 deleted from function.strpos by nlopess
| From: | nlopess@php.net | Date: | Sun, 16 May 2004 09:12:29 +0000 |
| Subject: | note 42400 deleted from function.strpos by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69662@lists.php.net to get a copy of this message | ||
Note Submitter: Louis Mullie
----
//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);
}
?>