Re: Copy and read a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



if you want to overwrite the file each time, then just use the "w" flag,
which will open, and clear the contents of the file preparing it for
writing, instead of "r".
check out the file commands on php.net.--
http://www.php.net/manual/en/function.fopen.php -- quite a bit of
flexibility is offered for stuff of this sort.

second, i'd use preg_match[_all] for searching through the file. you can
read it in with fread after it has been opened or use file(), then traverse
the array it returns searching for your content.  as with anything, i'm
sure there are other ways.

hth
jeff


                                                                                                                    
                    "Miguel Brás"                                                                                   
                    <molino26@netc       To:     php-db@lists.php.net                                               
                    abo.pt>              cc:                                                                        
                                         Subject:      Copy and read a file                                 
                    04/18/2003                                                                                      
                    08:04 AM                                                                                        
                                                                                                                    
                                                                                                                    




Hi gents,

I wanna copy a file from a webserver to my webserver everytime someone runs
the script A.

Someone gave me the following lines for it:

******************
$fp = fopen ("http://www.ivan.ivao.org/whazzup.txt";, "r");

while (!feof ($fp))
{
$buffer = fgets($fp, 10000);
$fo = fopen ("data_status.txt","a+");
fputs($fo,$buffer);
}
fclose ($fp);
fclose ($fo);

******************

For sure that this works, but it appends the new file, and i want to delete
all the old data and write the new one on the begin of the file.

Any idea for it?

The other part is that i wanna start on a specific point of the file and
make a search for a word. If i find the word, it continues to look until
eof. Then it returns me all the data found. Any help here also?

Miguel



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux