EchoFool Posted April 28, 2010 Share Posted April 28, 2010 Hey When i input to my database a message from a form that was typed into a text area - say there was paragraphs and gaps etc.. when the message is outputted at a later date the structure is lost and it is just a big chunk of text - this is happening for my forum posts but have no idea how to maintain the input structure upon output. Is there a a function of some kind for this solution? Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/ Share on other sites More sharing options...
trq Posted April 28, 2010 Share Posted April 28, 2010 nl2br sounds like what your after. Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1049701 Share on other sites More sharing options...
EchoFool Posted April 28, 2010 Author Share Posted April 28, 2010 Does it go on input and output or just output ? Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1049706 Share on other sites More sharing options...
trq Posted April 28, 2010 Share Posted April 28, 2010 Just output. Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1049711 Share on other sites More sharing options...
EchoFool Posted April 28, 2010 Author Share Posted April 28, 2010 Hmm doesn't seem to be the case. Still looses its structure, my input function has: mysql_real_escape_string(stripslashes($Var)); Could that cause structure loss? Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1050152 Share on other sites More sharing options...
trq Posted April 28, 2010 Share Posted April 28, 2010 No. What structure are you losing exactly. nl2br only appends <br /> tags to newlines. You might need to look at the user examples on the man page for some more comprehensive formatting functions. Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1050178 Share on other sites More sharing options...
EchoFool Posted April 28, 2010 Author Share Posted April 28, 2010 Well for example when you make a post here and press enter twice to make a gap line the gap line disappears so: Hello Hello Becomes: Hello Hello Which is annoying Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1050206 Share on other sites More sharing options...
trq Posted April 29, 2010 Share Posted April 29, 2010 nl2br should take care of that. You'll need to post some code if you need further help. Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1050242 Share on other sites More sharing options...
EchoFool Posted April 29, 2010 Author Share Posted April 29, 2010 Sure heres an example: INPUT FORM: <? function SQLskip($Var){ $Var = mysql_real_escape_string(stripslashes($Var)); return($Var); } if(isset($_POST['submit'])){ $Message = SQLskip($_POST['letter']); // insert query here }Else{ ?> <form method="POST" action=""> <textarea name="letter" class="textarea"> </textarea> <br><br> <input type="submit" name="submit" class="button" value=""><br><br> <a href="mail.php">Cancel Message</a><br> </form> <?php } ?> OUTPUT: //select query $QueryName $row = mysql_fetch_assoc($QueryName); echo nl2br($row['Message']); Field in database message example has the structure: http://i43.tinypic.com/sp887n.png Actual outputs: http://i42.tinypic.com/2mfiuxw.png So the input is fine as the structure remains in the database - its the output that goes wrong. Link to comment https://forums.phpfreaks.com/topic/199997-difficulty-with-structure-of-string/#findComment-1050310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.