Quick123 Posted August 28, 2010 Share Posted August 28, 2010 I've been making a program for school there is nothing wrong with the program itself except I don't know how to add line breaks inside a fwrite command. I'll show the code below so I can explain a little easier. The part in bold is where I need line breaks, any advice would be great. <html> <body> <form action="IO1.PHP" method="post"> <p> <label for="StrAccount"><b>Account:</b></label> <input type="text" name="StrAccount" id="StrAccount" /> <input type="submit" name="submit"/> </p> <?PHP /* Customers Information */ $Customer[0] = "Luiz Inácio Lula da Silva"; $Customer[1] = "J.T. Wang"; $Customer[2] = "Admiral Mike Mullen"; $Customer[3] = "Barack Obama"; $Customer[4] = "Ron Bloom"; $Phone[0] = "1234 5678"; $Phone[1] = "5678 1234"; $Phone[2] = "0000 1234"; $Phone[3] = "1234 0000"; $Phone[4] = "0000 0000"; $Title[0] = "The Shawshank Redemption"; $Title[1] = "The Godfather"; $Title[2] = "The Godfather: Part II"; $Title[3] = "Inception"; $Title[4] = "Sergio Leone's The Good, the Bad and the Ugly"; $Cost[0] = "$1.00"; $Cost[1] = "$2.00"; $Cost[2] = "$3.00"; $Cost[3] = "$4.00"; $Cost[4] = "$5.00"; $Return[0] = "01/01/2010"; $Return[1] = "01/02/2010"; $Return[2] = "01/03/2010"; $Return[3] = "01/04/2010"; $Return[4] = "01/05/2010"; if (isset($_POST["submit"])) { $Text = fopen ("Customers.txt", 'w'); $StrAccount = $_POST["StrAccount"]; if ($StrAccount == $Customer[0]) { echo "<p><b>$Customer[0], $Phone[0], $Title[0], $Cost[0], $Return[0]</b></p>"; fwrite ($Text, $Customer[0]); fwrite ($Text, $Phone[0]); fwrite ($Text, $Title[0]); fwrite ($Text, $Cost[0]); fwrite ($Text, $Return[0]); } elseif ($StrAccount == $Customer[1]) { echo "<p><b>$Customer[1], $Phone[1], $Title[1], $Cost[1], $Return[1]</b></p>"; fwrite ($Text, $Customer[1]); fwrite ($Text, $Phone[1]); fwrite ($Text, $Title[1]); fwrite ($Text, $Cost[1]); fwrite ($Text, $Return[1]); } elseif ($StrAccount == $Customer[2]) { echo "<p><b>$Customer[2], $Phone[2], $Title[2], $Cost[2], $Return[2]</b></p>"; fwrite ($Text, $Customer[2]); fwrite ($Text, $Phone[2]); fwrite ($Text, $Title[2]); fwrite ($Text, $Cost[2]); fwrite ($Text, $Return[2]); } elseif ($StrAccount == $Customer[3]) { echo "<p><b>$Customer[3], $Phone[3], $Title[3], $Cost[3], $Return[3]</b></p>"; fwrite ($Text, $Customer[3]); fwrite ($Text, $Phone[3]); fwrite ($Text, $Title[3]); fwrite ($Text, $Cost[3]); fwrite ($Text, $Return[3]); } elseif ($StrAccount == $Customer[4]) { echo "<p><b>$Customer[4], $Phone[4], $Title[4], $Cost[4], $Return[4]</b></p>"; fwrite ($Text, $Customer[4]); fwrite ($Text, $Phone[4]); fwrite ($Text, $Title[4]); fwrite ($Text, $Cost[4]); fwrite ($Text, $Return[4]); } else { echo "<p><b>This Account Does Not Exist.</b></p>"; } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
litebearer Posted August 28, 2010 Share Posted August 28, 2010 "\n" is new line BTW you could shorten your code by using a variable for the Customer/phone/etc number. ie $what_cust_num = 1; echo "<p><b>$Customer[$what_cust_num], $Phone[$what_cust_num ], $Title[$what_cust_num ], $Cost[$what_cust_num ], $Return[$what_cust_num ]</b></p>"; $save_string = $Customer[$what_cust_num] . "|" . $Phone[$what_cust_num] . "|" . $Title[$what_cust_num] . "|" . $Cost[$what_cust_num] . "|" . $Return[$what_cust_num] . "\n"; fwrite ($Text, $save_string); would put all the info into one line, with pipe "|" as separator and a new line at the end Quote Link to comment Share on other sites More sharing options...
Quick123 Posted August 28, 2010 Author Share Posted August 28, 2010 Where would I place the break? Because I can't place it in any of the obvious locations without some kind of error. Sorry for the idiotic question, I've only started learning PHP. Quote Link to comment Share on other sites More sharing options...
Quick123 Posted August 28, 2010 Author Share Posted August 28, 2010 Where would I place the break? Because I can't place it in any of the obvious locations without some kind of error. Sorry for the idiotic question, I've only started learning PHP. I fixed it. 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.