View Single Post
  #2  
Old 08-10-2006, 02:49 PM
anastasia anastasia is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
anastasia is on a distinguished road
Default

Try this code

define ('DATA_FILE', 'c:\myfile.txt');

if (!file_exists(DATA_FILE))
{
die ('File not found: '.DATA_FILE);
}

$data = file_get_contents(DATA_FILE);
$replacementText = 'HERE GOES THE HEADER';

$data = preg_replace('/<head>(.*)<\/head>/msiU', $replacementText, $data);

$fd = fopen('w+', DATA_FILE);
fwrite($fd, $data);
fclose($fd);

Best of luck -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  Webmaster Forums - View Single Post - replacing contents of a text file
View Single Post
  #2  
Old 08-10-2006, 02:49 PM
anastasia anastasia is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
anastasia is on a distinguished road
Default

Try this code

define ('DATA_FILE', 'c:\myfile.txt');

if (!file_exists(DATA_FILE))
{
die ('File not found: '.DATA_FILE);
}

$data = file_get_contents(DATA_FILE);
$replacementText = 'HERE GOES THE HEADER';

$data = preg_replace('/<head>(.*)<\/head>/msiU', $replacementText, $data);

$fd = fopen('w+', DATA_FILE);
fwrite($fd, $data);
fclose($fd);

Best of luck -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote