POC0bob Posted January 16, 2013 Share Posted January 16, 2013 Hello, this is a little complicated but I hope I can explain this well enough to get a good answer. So, what I need is a div, or something to display text like a text box, including all the spaces and enters and things that would normally show up in a text box, but still work with HTML code, like links and things, and display those correctly. I am creating a user message system that has some basic HTML features, such as links and stuff, but when I use it as a div, its all on one line and stuff.. Also, another side note, is there a way to protect me from other users putting HTML code in the messages, and it running when they view the mail? All I want it to do is display the HTML code the functions generate before the message is loaded to the client. (PHP) If you have any other questions, please ask. Thanks -POC0bob Quote Link to comment https://forums.phpfreaks.com/topic/273223-div-or-somthing-work-like-textbox/ Share on other sites More sharing options...
kicken Posted January 16, 2013 Share Posted January 16, 2013 Use a <pre> tag to preserve whitespace. Or apply the white-space: pre; setting via CSS to your div. Quote Link to comment https://forums.phpfreaks.com/topic/273223-div-or-somthing-work-like-textbox/#findComment-1406036 Share on other sites More sharing options...
Jessica Posted January 16, 2013 Share Posted January 16, 2013 It sounds to me like you should look into something like TinyMCE. Quote Link to comment https://forums.phpfreaks.com/topic/273223-div-or-somthing-work-like-textbox/#findComment-1406099 Share on other sites More sharing options...
DavidAM Posted January 16, 2013 Share Posted January 16, 2013 also, Use htmlspecialchars to convert HTML into displayable entities. Quote Link to comment https://forums.phpfreaks.com/topic/273223-div-or-somthing-work-like-textbox/#findComment-1406111 Share on other sites More sharing options...
Psycho Posted January 16, 2013 Share Posted January 16, 2013 (edited) also, Use htmlspecialchars to convert HTML into displayable entities. And I would follow that up with nl2br() to convert line breaks to <br> tags. Just be sure to do that after htmlspecialchars or else you will conver the br tags to textual content. EDIT: You did state you wanted to preserve 'spaces'. In which case PRE, as Kicken suggested, is the way to go. And if you do implement that, then you do not want to use nl2br(). Basically, there are several solutions and each has things it can and can't do. You'll need to determine exactly what you want to implement the best solution. Edited January 16, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/273223-div-or-somthing-work-like-textbox/#findComment-1406158 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.