alphazulu Posted June 7, 2011 Share Posted June 7, 2011 Ok, So, This has been on my nerves for a few days now The point of this is not too actually write to a file, but while I am testing I have it just writing to a file, later on it will edit a Wordpress page, and some other stuff First it reads from a file and gets a list of other files, next it opens a file, stores it in an array and should append it to a file, then repeat, adding the contents of each file to the end of the file. However, all it is doing is taking the contents of the first file and putting that intp the file. Here is the code, what am I missing? I feel like its right in front of me.. $master = "master.txt"; $mlines = count(file($master)); $mlines = $mlines - 1; $cat = array(); $files = array(); $ah = fopen($master, 'r'); $temp = fgets($ah); $cat = explode("=", $temp); fclose($ah); for($b = 0; $b <= $mlines; $b++){ $fh = fopen($cat[$b], 'r'); $lines = count(file($cat[$b])); $lines = $lines - 1; for($c = 0; $c <= $lines; $c++){ $files[$c] = fgets($fh); lp_post($files[$c]); } fclose($fh); } function lp_post($files){ $text = "text.txt"; $h = fopen($text, 'a'); fwrite($h, $files); fclose($h); } Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 7, 2011 Share Posted June 7, 2011 file_get_contents(); .. file_put_contents(); Quote Link to comment Share on other sites More sharing options...
alphazulu Posted June 8, 2011 Author Share Posted June 8, 2011 hey neat never seen that function before, playing with it now thank you Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 8, 2011 Share Posted June 8, 2011 try something like this: $allText = ''; $masterFile = file_get_contents('master.txt'); $filenames = explode("\n",$masterFile); foreach($filenames as $file){ $allText .= "\n".get_file_contents($file); } file_put_contents('text.txt',$allText); Quote Link to comment 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.