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

Can this be done?

P: n/a
Ken
How do I save the values (not variables) for the variables in a file?

Example:
$_SESSION['category'] = "TEST";
$url_read = readfile.php;
$url_write = writefile.php;

$sort = "var ".$_SESSION['category'];

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

// write to file
$f_w = file($url_write);
$write_file = fopen($url_write, "wb");

$key="sort";
foreach($f_r as $line) {
$sorte = strstr($line, $key); //look for $key in each line
fwrite($write_file,$sorte);
}
fclose($write_file);
fclose($read_file);

The results of the above in writefile.txt is sort = "var
".$_SESSION['category'];
In the writefile.txt, I am looking for: var TEST

I have tried several approaches with no results.

Thanks for the help.

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


P: n/a

Ken wrote:
How do I save the values (not variables) for the variables in a file?

Example:
$_SESSION['category'] = "TEST";
$url_read = readfile.php;
$url_write = writefile.php;

$sort = "var ".$_SESSION['category'];
Why are you setting this? You're not using it later.

// read file
$f_r = file($url_read);
$read_file = fopen($url_read, "r");
Don't need the above line, you've already read the file.
// write to file
$f_w = file($url_write);
Don't need the above line. Why are you reading in the file you're going
to be writing?
$write_file = fopen($url_write, "wb");

$key="sort";
foreach($f_r as $line) {
$sorte = strstr($line, $key); //look for $key in each line
What does the variable $sorte contain here?
fwrite($write_file,$sorte);
The above writes the value of $sorte to the file.
}
fclose($write_file);
fclose($read_file);
If you remove the fopen for $read_file, remove the above also.

The results of the above in writefile.txt is sort = "var
".$_SESSION['category'];
In the writefile.txt, I am looking for: var TEST

I have tried several approaches with no results.


What have you tried?

Tell us or show us what's in your input file. What do you expect to get
out as a result?

Ken

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.