Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to a file

Status
Not open for further replies.

tanveer91

Programmer
Nov 13, 2001
31
GB
Hi all,

I'm having problems creating files using fopen and fputs function. I don't know how to create a file that use strings which contain variables........is it that possible???

here's my code:

$fp=fopen(&quot;results/$matchdate&quot;, &quot;w&quot;);$string = &quot;<td align=left>$score</td>&quot;;
fputs($fp,$string);
fclose($fp);

is this possible??.....ur help is much appreciated!
 
I'm new to PHP myself, but here's how I wrote variables to a flat file: (This solution was recommended by Hokey, a few days ago.)

<?php
$record = &quot;${name}:${age}:${race}:${gender}:${status}\n&quot;;
$fp = fopen(&quot;/tmp/form.out&quot;,&quot;a&quot;);
fputs($fp,$record,strlen($record));
fflush($fp);
fclose($fp);
?>
 
yes you can, but you have to put single quotes instead of double ones:

$string = '<td align=left>$score</td>';


This way the string will not evaluate the var and will write the dollar sign and the name of it directly in the output (in this case, the file).
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top