Ryan_w Posted June 8, 2007 Share Posted June 8, 2007 Hey, New to the whole PHP ting, so I am muddling through. Trying to write the output of 3 array values to a file with fwrite(). Right now I am getting a never ending loop outputting "264" all on the same line. $fp = fopen('text.file', 'a'); $count = 1; while ($count < $finish) { fwrite($fp, "$idarray[$count] $pwarray[$count] $rankarray[$count]"); } fclose($fp); the values coming out of the arrays are: idarray - 6 character integer pwarray - 6 to 20 character alpha numeric rankarray - 2 character integer I am attempting to get a text file like: 123456 jf0mklf9 12 123456 jkfldjioenklf 12 123456 j40fGF4jnf99 12 etc.... Any help would be greatly appreciated. Ryan Quote Link to comment https://forums.phpfreaks.com/topic/54716-trying-to-fwrite-several-formatted-array-values/ Share on other sites More sharing options...
Stuie_b Posted June 8, 2007 Share Posted June 8, 2007 You dont seem too be incrementing the count variable? which means the value of $count will remain 1 and will cause the while loop to never end, try the following edit $fp = fopen('text.file', 'a'); $count = 1; while ($count < $finish) { fwrite($fp, "$idarray[$count] $pwarray[$count] $rankarray[$count]"); $count++; //Add 1 each time the loop is run. } fclose($fp); by adding $count++; too the while you are telling php too add 1 each time it's looped through, (it's the same as $count = $count+1;) hope it helps Stuie Quote Link to comment https://forums.phpfreaks.com/topic/54716-trying-to-fwrite-several-formatted-array-values/#findComment-270696 Share on other sites More sharing options...
Ryan_w Posted June 8, 2007 Author Share Posted June 8, 2007 Cool....thanks for the advice on incrementing the counter. I have only one more problem.....the data is now being outputted properly with the exception that it is coming out all on one line in the file rather than one set of values per line. eg: rather than this: 123456 jf0mklf9 12 123456 jkfldjioenklf 12 123456 j40fGF4jnf99 12 I get this: 123456 jf0mklf9 12123456 jkfldjioenklf 12123456 j40fGF4jnf99 12 Any Suggestions? Thanks in advance, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/54716-trying-to-fwrite-several-formatted-array-values/#findComment-270876 Share on other sites More sharing options...
Ryan_w Posted June 8, 2007 Author Share Posted June 8, 2007 Nevermind, I finally figured it out....chr(10) is my friend Thx for the help guys. Quote Link to comment https://forums.phpfreaks.com/topic/54716-trying-to-fwrite-several-formatted-array-values/#findComment-270955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.