Baxt01 Posted September 19, 2013 Share Posted September 19, 2013 i have a form with a <textarea> on it and the usser will submit a list into the text area once they click submit this list is saved into a .txt file on my server the usser's list is formatted as item1 item2 item3 item4 item5 item6 item7 item8 item9 item10 and so on, when they hit submit and this list is saved in my .txt file the list becomes item1item2item3item4item5item6item7item8item9item10andsoon then once saved i am ussing the php to display this on the ending page like this <?php include('top100stats.txt'); ?> to open the contents of the txt file i need some how to keep the orignal list formatting so that each item is on a new line of course there is the list tags <li> but how do i add this tags to my saved .txt file Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/ Share on other sites More sharing options...
cataiin Posted September 19, 2013 Share Posted September 19, 2013 (edited) <form method="post"> <textarea name="textarea"></textarea> <input type="submit" /> </form> <?php $file = "text.txt"; $text = $_POST["textarea"]; $text_ok = nl2br($text); file_put_contents($file, $text_ok); include "text.txt"; ?> Edited September 19, 2013 by cataiin Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1450330 Share on other sites More sharing options...
Barand Posted September 20, 2013 Share Posted September 20, 2013 cataiin, No. Use nl2br() on output in the browser. Store data with just the newlines. Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1450488 Share on other sites More sharing options...
cataiin Posted September 21, 2013 Share Posted September 21, 2013 (edited) cataiin, No. Use nl2br() on output in the browser. Store data with just the newlines. Yes, you're right! My mistake, sorry. Edited September 21, 2013 by cataiin Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1450509 Share on other sites More sharing options...
Baxt01 Posted September 23, 2013 Author Share Posted September 23, 2013 sorry been offline a little while here just startted back into full time employement haha, think i am missing my computer already, thanks for the help but yet again i hit another issue now i am startting to wonder why i want to learn php i have so many issues with my codes, here is my script so far: <?php $player_name = $_POST['player_name'];$fp = fopen('top100stats.txt', 'w'); fwrite($fp, $player_name); fclose($fp);echo '<h2>You data has been saved in a text file!</h2>'; ?> ok i thought i was getting there when i submitted my form and i recived back the message from the "echo" However when i go onto my server and open top100stats.txt it is blank there are no saved records so the server is telling me that a record has been creatted but in fact it is not anyone got any idea why its not saving and not giving an error???????????? Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1450951 Share on other sites More sharing options...
DFulg Posted September 23, 2013 Share Posted September 23, 2013 (edited) Make sure your error_reporting is set to E_ALL or -1 and display_errors is set to 'On' or 1. You should be receiving some kind of error. In any case, add some debugging: $fp = fopen('top100stats.txt', 'r'); //open the file read-only to verify that it exists. if ( $fp === false ) { //cannot open the file echo "Error while attempting to open the file."; } else { // file opened successfully, display message echo '<h2>File exists!</h2>'; } Edited September 23, 2013 by DFulg Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1450952 Share on other sites More sharing options...
Solution Baxt01 Posted September 26, 2013 Author Solution Share Posted September 26, 2013 ok now i again thank you all for been so kind with promp helping of me; and have to say i think the reason i am loving learning PHP is that any error i have had so far is usually dumb and i can work it out with little prompts i just have to go away to work and come back and take a frsh look at my coding and suddenly the issue pops right out at me hahaha i was putting the coding that catain gave me into the wrong file and forgot to change the field names to match my form fields /DOH thanks again peoples Quote Link to comment https://forums.phpfreaks.com/topic/282298-how-can-i-give-text-html-formatting-after-a-usser-subits-a-form/#findComment-1451234 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.