View Full Version : formating output from a database in an HTML page
pthompson2002
09-30-2002, 01:21 PM
Is it possilbe to format the look of the data that a user pulls out of the database into an HTML page?
Our users can retrieve text, of up to 2000 characters, from a database. This text was entered by the user in a textarea and can be retrieved to the text area with the formatting used still present. However if the data is retrieved directly to HTML there is no formatting and the text appears in one big line. I sthere a way to automatically ad in <p> tags using JavaScript?
ShriekForth
09-30-2002, 04:11 PM
I would not user ajavascrip tto do this, You could capture the entry and insert it into the database with the \n removed and replaced with <br> or <p> tags.
You could also display the contents of the database field in <pre> tags. If the control characters are stored in the data still, this will use it in display. You can tell by looking at the source of the page as it is displaying now. If it is all oneone line, then this method will not work. If it is on multiple lines in the source, it will work just fine.
ShiekForth
pthompson2002
09-30-2002, 04:34 PM
How would I go about capturing the entry? Retrieving the data into the textarea keeps the formatting but obviously there are no HTML tags in the text so when it is dipslayed in a webpage it is just a striaght line so <pre> won't work
ShriekForth
09-30-2002, 05:06 PM
This should go to another message board, as it will need to be done server side. What language is it written in? The syntax will vary language to language, but the idea is the same, you need to use a regular expression replacement on the input from the user to replace the special characters to <br>'s. In php there is a function called nl2br. In most other languages it would be some kind of string_replace("\n","<br>"); In unix it's "\n\r" newling carridge return. After this has happened, THEN store it in the DB, it will take a few extra bytes, but if it is already stored this way, you can just run the input through this before display.
ShriekForth
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.