Jump to content


DIV (or somthing) Work like textbox

  • Please log in to reply
4 replies to this topic

#1 POC0bob

  • Members
  • PipPip
  • Member
  • 11 posts

Posted 16 January 2013 - 06:09 AM

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 :)

#2 kicken

  • Gurus
  • Wiser? Not exactly.
  • 3,313 posts
  • LocationBonita, FL

Posted 16 January 2013 - 06:32 AM

Use a <pre> tag to preserve whitespace.  Or apply the white-space: pre; setting via CSS to your div.
Did I help you out? Feeling generous? I accept tips via Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7
Kicken's World⦄ ⦃Recycle old CD's

#3 Jessica

  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 16 January 2013 - 01:04 PM

It sounds to me like you should look into something like TinyMCE.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 DavidAM

  • Moderators
  • Advanced Member
  • 1,980 posts
  • LocationSpring, TX USA

Posted 16 January 2013 - 01:40 PM

also, Use htmlspecialchars to convert HTML into displayable entities.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#5 Psycho

  • Moderators
  • Move along, nothing to see here
  • 11,846 posts
  • LocationCanada

Posted 16 January 2013 - 06:49 PM

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 by Psycho, 16 January 2013 - 06:51 PM.

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users