Forum Moderators: coopster

Message Too Old, No Replies

simplify fputs()

contraction

         

WhosAWhata

3:18 am on Jan 27, 2004 (gmt 0)

10+ Year Member



i am currently using code that resembles this:
fputs($cmke,"<? \$first=\"");
fputs($cmke,$first);
fputs($cmke,"\"; \$last=\"");
fputs($cmke,$last);
fputs($cmke,"\"; \$username=\"");
fputs($cmke,$username);
fputs($cmke,"\"; \$password=\"");
fputs($cmke,$mypass);
fputs($cmke,"\";?>");
this isn't too bad, but in reality i have many more variables, i'd like to turn this into just one fputs() command is that possible?
My script isn't done yet so i can't test, but i would assume that it could be written like this:

fputs($cmke,"<? \$first=\"" . $first . "\"; \$last=\"" . $last . "\"; \$username=\"" . $username . "\"; \$password=\"" . $mypass . "\";?>");

is this right?

jatar_k

12:31 am on Jan 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



does it actually work WhosAWhata?

BitBanger

1:46 am on Jan 28, 2004 (gmt 0)

10+ Year Member



Rather than all the extra quotes and concantinations try something like this:

fputs($cmke,"<? \$first=\"{$first}\"; \$last=\"{$last}\"; \$username=\"{$username}\"; \$password=\"{$mypass}\";?>");

I use this sort of structure all the time to output HTML.

WhosAWhata

10:31 pm on Jan 28, 2004 (gmt 0)

10+ Year Member



as a matter of fact,
both of these strange structures seem to work, i placed them in a blank php file and went to file.php?first=this&last=that&username=something
and it created a file with the desired contents
THANKS

mykel79

10:50 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



You can also try heredocs.

$body=<<<END
this is the
body I want
to enter into
a file!
END;

fputs($cmke,$body);

I'm just not sure if the <? won't mess things up. I definitely works otherwise, because I do it myself often.