Forum Moderators: coopster
The contents of this file is updated once in a while and basically I need a php script that will open this file, read it and then remove certain things and then save a copy locally.
The contents of this file looks as follows:
Volume in drive C has no label.
Volume Serial Number is A85F-F7AD
Directory of C:\test
[code]
10/01/2007 01:36 PM <DIR> .
10/01/2007 01:36 PM <DIR> ..
10/01/2007 01:32 PM <DIR> abc
10/01/2007 01:32 PM <DIR> 123
10/01/2007 01:32 PM <DIR> def
10/01/2007 01:32 PM <DIR> 456
0 File(s) 0 bytes
7 Dir(s) 68,797,751,296 bytes free i want to get rid of the first 7 lines of the file and the last 3 lines. and then on each line i want to get rid of everything before the <DIR> including the <DIR> aswell.
can anyone please help me and tell me how this can be achieved. thank you
[edited by: dreamcatcher at 1:26 pm (utc) on Oct. 1, 2007]
[edit reason] Use example.com, thanks. [/edit]
currently i have managed to get the file and read like this:
$content = file_get_contents('http://www.example.com/output.txt');
if ($content!==false) {
echo $content;
}else {
}
[edited by: dreamcatcher at 1:32 pm (utc) on Oct. 1, 2007]
[edit reason] Use example.com, thanks. [/edit]
$inputfile = fopen("http://www.example.com/output.txt", "r");
if(!$inputfile )
{
echo "File Not Found";
exit;
}
$outputfile = fopen("/path/to/local/file.txt", "w");
if(!outputfile )
{
echo "Unable to open/create local file";
fclose( $inputfile );
exit;
}
while(!feof( $inputfile ) )
{
$buf = fgets( $inputfile, 2048 );
$yourdata = explode( "<DIR> ", $buf );
if( $yourdata[1] )
fwrite( $outputfile, $yourdata[1] );
}
fclose( $inputfile );
fclose( $outputfile );
// remove 7 lines
array_splice($content, 0, 7);
foreach($content as $key => $line) {
$content[$key] = preg_replace('/.*(\<DIR\>)/','',$line);
}
Resulting array will be in the $content
You can convert it into single string using $string = implode('',$content);