View Full Version : Server side alternative to "<pre>"

01-13-2005, 07:26 AM
Okay here is the problem I have.

Users enter data into a textbox... and I write it to my database. However when I retrieve the data from my database, the layout is completely changed. That is, where the user pressed enter and so on.... all the text is jumbled.

I have tried my luck with the "<pre>" tag but that gave me one everlasting line that streched out my page a few screen sizes to the right depending on how long the line was?

It was suggested to me that i need to forget the "<pre>" tag and use a server side method to store/display the code in such a way that it appears as it does in this forum. That is, no matter how much text we type... wherever we press enter it is conserved in the display of the post.....

01-13-2005, 04:37 PM
im not really sure what your question is but the vbNewLine constant is used for a new line in the source, <br> is used for a newline in the page..


'how are you?
strString = "hello" & vbNewline & "how are you?"

'hello<br>how are you?
strHTMLOutput = Replace(strString, vbNewLine, "<br>")

'how are you?
strPreOutput = Replace(strString, vbNewLine, "<br>" & vbNewLine)

01-13-2005, 05:18 PM
Yo ghell, just kno that u the boss! Thanks man.... i've spent weeks trying to get around this problem.

I've tried asking the same question different ways in different forums tryin to get a response and all sounded good at face value but thnx alot man!!!!

Works lke a charm :thumbsup: :D :thumbsup: :D :cool: :p :) :rolleyes: :cool:

01-14-2005, 10:43 AM
yaaay :D

on a sidenote, i didnt mention though that pre does other things, it keeps whitespace and writes in a monospace font

to keep whitespace replace " " with "&nbsp;" and similar with tabs (4 or 8 spaces, or theres probably a tab in the iso character table somewhere)

note: one space is fine, so

" " = " "
" " = " "
" &nbsp; " = " "
so it would be more efficient to just replace " " with " &nbsp;"i think :thumbsup:

monospace fonts can be done by using a monospace font (ie courier [use this its the standard one], courier new, lucidia console) or typewriter tags (<tt>..</tt>)

01-14-2005, 11:54 AM
If your users are going to be able to edit these fields later, you might want to save both their submitted original, and the 'fixed' version in your database.

When they edit the record, you serve the original version they typed to the editing page. Otherwise you'll be sending the fixed version, and unless you reverse the changes you made the textarea the user sees will be full of code they don't recognise.

01-14-2005, 01:13 PM
thanks i'll see how that works.... i'm a gonna give that a try