By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Save data not variables in a file

P: n/a
Ken
I am try to save the "values" of variables from a file (template.php) to
another file (tmp.txt).

$value = "12345";

template.php
<?php
The answer is $value. //When viewing the file, I see 12345.
?>

tmp.txt
The answer is 12345. This is what I am trying to do.

The answer is $value. This is the results of the following script.

When I write the data to tmp.txt, the variable is copied, not the
value of the variable.

How do I write (save) the results of the template.php in tmp.txt?

<?php
$url_read = $_SESSION['folder_dir']."template.php";
$url_write = $_SESSION['folder_dir'].'tmp.txt';

$f_r = file($url_read);
$read_file = fopen($url_read, "r");

$f_w = file($url_write);
$write_file = fopen($url_write, "wb");
foreach($f_r as $line) {
fwrite($f_w,$line);
}
fclose($read_file);
fclose($write_file);

Thanks


Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ken wrote:
I am try to save the "values" of variables from a file (template.php)
to another file (tmp.txt).

$value = "12345";

template.php
<?php
The answer is $value. //When viewing the file, I see 12345.


tmp.txt
The answer is 12345. This is what I am trying to do.

The answer is $value. This is the results of the following script.

When I write the data to tmp.txt, the variable is copied, not the
value of the variable.

How do I write (save) the results of the template.php in tmp.txt?


$url_read = $_SESSION['folder_dir']."template.php";
$url_write = $_SESSION['folder_dir'].'tmp.txt';

$value = "12345";

ob_start();
include $url_read;
$f_r = ob_get_contents();
ob_end_clean();

$write_file = fopen($url_write, "ab");
fwrite($write_file, "$f_r\n");
fclose($write_file);
JW

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.