Using a textarea input what is the correct way to preserve whitespace?
coopster
12:35 am on Mar 25, 2006 (gmt 0)
Not sure what you mean by preserving whitespace? You mean if you read it in and display the information back out again?
mealybar
12:48 am on Mar 25, 2006 (gmt 0)
I've got a text area, passed back through validation in php and saved to a text file, which is then used in some content on my site. If a user uses some spaces to emphasise a point or tabs to make an indent or rough table its being reverted back to the html 1 space.
Sure I've seen it before just cant remember, could be php function or html tag?
barns101
9:58 am on Mar 25, 2006 (gmt 0)
HTML ignores multiple spaces (not sure about tabs but I doubt they would appear the same as in a word processor document either). You could replace multiple spaces with their HTML equivalent ( ) in order to preserve formatting.
Alternatively you can use the preformatted text <pre> tag to preserve space. You could then add a style to this to format the font etc...
coopster
5:54 pm on Mar 25, 2006 (gmt 0)
nl2br [php.net] will return a string with '<br />' inserted before all newlines, is that what you are looking for?