PHP: Can I put a for loop into the fwrite function?

Oct 19, 2000
17,860
4
81
I'm wanting to take the submitted values of a form to create a text file. Normally, the script will create a one line text file, but occassionally I'll need to submit this same one line a specified number of times in this same text file.

To achieve this, I was trying to use an IF to see if I have called for the submitted values to be repeated. If I have, then I'll call the fwrite function, specify my file handle variable that's set up, then I was trying to use a for loop to loop the code that writes that line to the text file.

It's not working, though, and I'm 100% sure that my syntax isn't correct, that's why I'm not even bothering posting it here. I've never attempted using a for in an fwrite function, so I don't know how it should be structured.

Can I get some help on this?

EDIT: After giving it some more thought and looking through some stuff, I'm thinking that I need to use a for loop to simply append the data instead of trying to do everything in one step. I may be right, I may be wrong, but that's what I'm going to try. I still appreciate any advice on the matter. :)
 

drebo

Diamond Member
Feb 24, 2006
7,034
1
81
If I recall correctly, fwrite() simply takes a string and writes it to a file.

You might try constructing the string with all its components (which variables get repeated, etc) and then writing it at the end, after all is said and done.

Why don't you post your code so we can see if there are any glaring mistakes? Hard to diagnose those without the code...
 
Oct 19, 2000
17,860
4
81
Originally posted by: drebo
If I recall correctly, fwrite() simply takes a string and writes it to a file.

You might try constructing the string with all its components (which variables get repeated, etc) and then writing it at the end, after all is said and done.

Why don't you post your code so we can see if there are any glaring mistakes? Hard to diagnose those without the code...

I don't want to post the code since it's stuff for work, possibly confidential even though it's simple in nature. I've modified the code to do what I said I was going to do in my edit of the original post, but your idea sounds like it will cause less overhead, so I'll give it a whirl.