zenix Posted July 18, 2009 Share Posted July 18, 2009 Hi, I am trying to learn php and have been making some pretty good progress. I've just run into a wall though and would REALLY appreciate it if someone could let me know what I am doing wrong. I have this fictitious order form that when filled out a new web page is displayed with the info. and the text is written in tab delimited style to a text file. I'd like to have it so each entry receives its own line. I have utilized \n to no avail, and have tried using <br /> and <p>, none of them give me a new line each time the form is submitted. Thank you in advance! Here is my code. <?php include ('error.php'); $modem = $_POST['modem']; $enet =$_POST['enet']; $sound =$_POST['sound']; $DOCUMENT_ROOT= $_SERVER['DOCUMENT_ROOT']; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; ?> <br><br> <html><head><title>ZENIX COMPUTERS</title></head><body> <h1><i>ZENIX COMPUTERS</h1></i> <br> <h2>Order results</h2> <br><p>Order submitted: <?php echo date('H:i, F jS')?> <br><br> <?php $date = date('H:i, F jS'); $find = $_POST['find']; echo "You stated you were referred to us via <b><i> $find</b></i>"; ?> <br><br><?php echo "Your order is as follows:<br>"; echo $modem . 'Modem(s)<br>'; echo $enet .'Ethernet Card(s)<br>'; echo $sound .'Sound card(s)<br>'; ?> <br> <? echo "The subtotal of your order is $tamount";?> <br><? echo "The tax on this order will be $tax";?> <br><? echo "Bringing the total for your order to $grandt";?> <?php $total = 0; $total = $modem +$enet +$sound; if ($total == 0) { echo "You didn't order anyting"; } else { if($modem >0) echo $modem. 'Modem(s)'; if($enet >0) echo $enet. 'Ethernet card(s)'; if ($sound >0) echo $sound. 'Sound card(s)'; } $tamount = 0.00; define('modemp', 19.95); define ('enetp', 19.95); define('soundp', 24.95); $tamount = $modem * modemp + $enet * enetp + $sound * soundp; $tax = $tamount * .08; $grandt = $tamount + $tax; echo 'Items ordered: '.$total.'<br>'; echo 'Your sub total for this order is <font color="blue"><b><i>$'.number_format($tamount,2).'</font></b></i><br>'; echo 'The sales tax will be<b><i><font color="blue">$'.number_format($tax,2).'</font></b></i><br>'; echo '<br>Bringing your total order with tax to<b><i><u><font color="blue">$'.number_format($grandt,2).'</font></b></i></u>'; echo "<br><br>"; $output = '<p>'.$date. "\t".$modem." modem \t" .$enet." Ethernet card \t" .$sound." Sound card\t$" .$grandt." TOTAL\t".$lname." Last\t".$fname." First\t".$address." Address\t".$address2." Address 2\t".$city." City\t".$state." State\t".$zip." Zip\t".$phone."\n"; //append file $fp = fopen("DOCUMENT_ROOT/../orders/orders.txt", 'ab'); if (!$fp) { echo 'Your order could not be processed at this time, please try again later.'; exit; } fwrite($fp, $output, strlen($output)); if($fp) { echo 'DONE!!'; } fclose($fp); echo 'Order written to file'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166419-new-line-in-txt-file/ Share on other sites More sharing options...
redarrow Posted July 18, 2009 Share Posted July 18, 2009 \n new line. Linux way. \n\t windows way Quote Link to comment https://forums.phpfreaks.com/topic/166419-new-line-in-txt-file/#findComment-877590 Share on other sites More sharing options...
benphelps Posted July 18, 2009 Share Posted July 18, 2009 \r also simulates the pressing of the return key (Enter) Quote Link to comment https://forums.phpfreaks.com/topic/166419-new-line-in-txt-file/#findComment-877592 Share on other sites More sharing options...
wildteen88 Posted July 18, 2009 Share Posted July 18, 2009 \n\t windows way Newlines for windows is \r\n \t is for tab Quote Link to comment https://forums.phpfreaks.com/topic/166419-new-line-in-txt-file/#findComment-877602 Share on other sites More sharing options...
zenix Posted July 18, 2009 Author Share Posted July 18, 2009 Thank you so much everyone!! It's been a headache. Quote Link to comment https://forums.phpfreaks.com/topic/166419-new-line-in-txt-file/#findComment-877604 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.