...

View Full Version : write to text file help



scroots
04-16-2003, 07:18 PM
if i have
<?php
$person = "Bob";
$var = "doodah";
$file = "file.txt";
?>

how can i write the variables ($person and $var)to a text file which is defined by a variable ($file)itself.


scroots

ASAAKI
04-16-2003, 08:30 PM
try:



<?php

$person = "Bob";
$var = "doodah";
$file = "file.txt";

$fp = fopen($file,'a+');
/* the "a+" is for opening the file in read-write mode and appending to its contents */

fwrite($fp, $person);
fwrite($fp, $var);

?>



oughta work i guess.

scroots
04-16-2003, 08:44 PM
i don't think its your code but i get
Parse error: parse error in c:\phpdev\www\text write\doit.php on line 5

and yes my php stuff does work as i can do the hello world test.

any ideas?

scroots

ASAAKI
04-16-2003, 09:04 PM
hmmm..
maybe u made a little mistake in copying?
coz i tried it and it's okay.

copy and paste what code u've got.

ps. btw i forgot to close the filestream(?) at the end:


fclose($fp);

ASAAKI
04-16-2003, 09:08 PM
if u simply copied and pasted my code then u might have accidentally made some mistake in these two lines:

$person = "Bob";
$var = "doodah";

scroots
04-16-2003, 09:45 PM
i will fiddle and faf tomorrow as its late now.

thanks so far

scroots



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum