Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: write to text file help

1. ## write to text file help

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

2. try:

PHP Code:
 <?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. 3. 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 4. 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: PHP Code:  fclose($fp);  

5. if u simply copied and pasted my code then u might have accidentally made some mistake in these two lines:

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

6. i will fiddle and faf tomorrow as its late now.

thanks so far

scroots

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•