Connecting Tech Pros Worldwide Help | Site Map

Copy data between files

Ken
Guest
 
Posts: n/a
#1: Jul 17 '05
How do I copy data from one file to another? from $_SESSION['fname'] to
"fname"

datafile.php has

fname: $_SESSION['fname'];
lname: $_SESSION['lname'];

I would like to automatically copy the data to

second.js

var fname = "fname";
var lname = "lname";

to be used in JavaScript.

I am familiar with
$contents = file_get_contents($filename);

and I know how to copy files but not data inside of the file.

Thanks for the help.

Ken




Erwin Moller
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Copy data between files


Ken wrote:
[color=blue]
> How do I copy data from one file to another? from $_SESSION['fname'] to
> "fname"
>
> datafile.php has
>
> fname: $_SESSION['fname'];
> lname: $_SESSION['lname'];
>
> I would like to automatically copy the data to
>
> second.js
>
> var fname = "fname";
> var lname = "lname";
>
> to be used in JavaScript.
>
> I am familiar with
> $contents = file_get_contents($filename);
>
> and I know how to copy files but not data inside of the file.
>
> Thanks for the help.
>
> Ken[/color]


Hi Ken,

Have a look at:
http://nl2.php.net/manual/en/function.fopen.php

You will find a few examples and related functions over there.
It is not difficult.
1) Open a filehandle for the file to read.
2) Open a filehandle to the file to write to.
3) Walk though the first file and write stuff you want in the second file to
the second handle.
4) close both filehandles.

Good luck.
Regards,
Erwin Moller

Daniel Tryba
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Copy data between files


Ken <kkrolski@wi.rr.com> wrote:[color=blue]
> How do I copy data from one file to another? from $_SESSION['fname'] to
> "fname"
>
> datafile.php has
>
> fname: $_SESSION['fname'];
> lname: $_SESSION['lname'];
>
> I would like to automatically copy the data to
>
> second.js
>
> var fname = "fname";
> var lname = "lname";[/color]

You don't actually want to you copy that! fname and lname strike me like
lastname and firstname variables, so they are dependend on the user ->
session data.

So just serve the javascript by using php and you can use the session
data to dynmically set the values of [lf]name (don't forget to set hte
correct mimetype else strange things can happen).

Chung Leong
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Copy data between files


"Ken" <kkrolski@wi.rr.com> wrote in message
news:yuTXd.81$hu3.65@twister.rdc-kc.rr.com...[color=blue]
> How do I copy data from one file to another? from $_SESSION['fname'] to
> "fname"
>
> datafile.php has
>
> fname: $_SESSION['fname'];
> lname: $_SESSION['lname'];
>
> I would like to automatically copy the data to
>
> second.js
>
> var fname = "fname";
> var lname = "lname";
>
> to be used in JavaScript.
>
> I am familiar with
> $contents = file_get_contents($filename);
>
> and I know how to copy files but not data inside of the file.
>[/color]

Just do something like

echo <<<JS
<script>
fname = {$_SESSION['lname']};
lname = {$_SESSION['lname']};
</script>
JS;

Linked in Javascript code run in the same context as the HTML page. You
don't need to set the variables in the .js file itself.


Closed Thread