Connecting Tech Pros Worldwide Help | Site Map

Can this be done?

Ken
Guest
 
Posts: n/a
#1: Jul 17 '05
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


Ken Robinson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Can this be done?



Ken wrote:[color=blue]
> 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'];[/color]

Why are you setting this? You're not using it later.
[color=blue]
>
> // read file
> $f_r = file($url_read);
> $read_file = fopen($url_read, "r");[/color]

Don't need the above line, you've already read the file.[color=blue]
>
> // write to file
> $f_w = file($url_write);[/color]

Don't need the above line. Why are you reading in the file you're going
to be writing?
[color=blue]
> $write_file = fopen($url_write, "wb");
>
> $key="sort";
> foreach($f_r as $line) {
> $sorte = strstr($line, $key); //look for $key in each line[/color]

What does the variable $sorte contain here?
[color=blue]
> fwrite($write_file,$sorte);[/color]

The above writes the value of $sorte to the file.
[color=blue]
> }
> fclose($write_file);
> fclose($read_file);[/color]

If you remove the fopen for $read_file, remove the above also.
[color=blue]
>
> 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.[/color]

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

Closed Thread