Moron Posted March 9, 2011 Author Share Posted March 9, 2011 Can you post your most recent code now. Sure. It is: <?php $tmp = array(); ?> <?php $AccountNumber = "00040"; if ($AccountNumber = 00040) { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is 00040"; $tmp[] = "</ACCOUNT_NO>\n"; } else { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is not 00040"; $tmp[] = "</ACCOUNT_NO>\n"; $tmp[] = ''; } ?> <?php $AccountName = "Microsoft"; if ($AccountName = "Microsoft") { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is Microsoft"; $tmp[] = "</ACCOUNT_NAME>\n"; } else { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is not Microsoft"; $tmp[] = "</ACCOUNT_NAME>\n"; } ?> <?php file_put_contents('accounts.txt',implode("\n",$tmp)); ?> Link to comment https://forums.phpfreaks.com/topic/229987-writing-output-to-a-file/page/2/#findComment-1185011 Share on other sites More sharing options...
HuggieBear Posted March 9, 2011 Share Posted March 9, 2011 OK, I've tried this and it appears to be working: <?php // Declare Array $tmp = array(); // Hard coded details for testing $AccountNumber = "00040"; $AccountName = "Microsoft"; // Add Account Number if ($AccountNumber == "00040") { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is 00040"; $tmp[] = "</ACCOUNT_NO>"; } else { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is not 00040"; $tmp[] = "</ACCOUNT_NO>"; } // Attempt to add a new line to separate sections as implode wont add additional line $tmp[] = "\n"; // Add Account Name if ($AccountName == "Microsoft") { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } else { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is not Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } // Write contents to a file file_put_contents('accounts.txt',implode("\n",$tmp)); ?> Link to comment https://forums.phpfreaks.com/topic/229987-writing-output-to-a-file/page/2/#findComment-1185014 Share on other sites More sharing options...
Moron Posted March 9, 2011 Author Share Posted March 9, 2011 OK, I've tried this and it appears to be working: <?php // Declare Array $tmp = array(); // Hard coded details for testing $AccountNumber = "00040"; $AccountName = "Microsoft"; // Add Account Number if ($AccountNumber == "00040") { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is 00040"; $tmp[] = "</ACCOUNT_NO>"; } else { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is not 00040"; $tmp[] = "</ACCOUNT_NO>"; } // Attempt to add a new line to separate sections as implode wont add additional line $tmp[] = "\n"; // Add Account Name if ($AccountName == "Microsoft") { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } else { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is not Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } // Write contents to a file file_put_contents('accounts.txt',implode("\n",$tmp)); ?> I think it is. It seems that I get a different formatting with Notepad as opposed to Notepad++ as opposed to Wordpad, etc.... Thanks! I'll experiment with adding some more elements. Link to comment https://forums.phpfreaks.com/topic/229987-writing-output-to-a-file/page/2/#findComment-1185016 Share on other sites More sharing options...
HuggieBear Posted March 9, 2011 Share Posted March 9, 2011 If you're viewing and running on Windoze then you might want to try this, it should add the End Of Line character for that specific OS. On Windoze I believe it's "\r\n" <?php // Declare Array $tmp = array(); // Hard coded details for testing $AccountNumber = "00040"; $AccountName = "Microsoft"; // Add Account Number if ($AccountNumber == "00040") { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is 00040"; $tmp[] = "</ACCOUNT_NO>"; } else { $tmp[] = "<ACCOUNT_NO>"; $tmp[] = "Account Number is not 00040"; $tmp[] = "</ACCOUNT_NO>"; } // Attempt to add a new line to separate sections as implode wont add additional line $tmp[] = PHP_EOL; // Add Account Name if ($AccountName == "Microsoft") { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } else { $tmp[] = "<ACCOUNT_NAME>"; $tmp[] = "Account Name is not Microsoft"; $tmp[] = "</ACCOUNT_NAME>"; } // Write contents to a file file_put_contents('accounts.txt',implode(PHP_EOL, $tmp)); ?> Link to comment https://forums.phpfreaks.com/topic/229987-writing-output-to-a-file/page/2/#findComment-1185018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.