unexpected variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
defx
Forum Commoner
Posts: 36
Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA

unexpected variable?

Post by defx »

Code: Select all

function submit()
{
$outputstring = "test"
$fp = fopen("$file", "w");
fwrite($fp, $outputstring);}
}
Parse error: parse error, unexpected T_VARIABLE on line 27

Line 27 = closing bracket for function submit

Also, is it possible to write variables using fopen and fwrite? for example I want to write into a PHP file, $var1 = "variable 1"; how would I do that?
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

Code: Select all

<?php

function submit($file)
{
$outputstring = "test";
$fp = fopen($file, "w");
fwrite($fp, $outputstring);
}


submit('this_is_a_file.txt');
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

the only thing wrong int hat is you missed a semi-colon (;) at teh end of the $outputstring line.

And yes you can write to a PHP file. do it the same way:

Code: Select all

$tmp = "\$var1 = "variable 1"\;";
But oyu would first have to parse throught he PHP file and add it where you wanted... not as easy as you want it to be!
Post Reply