On 12/11/2004, at 4:05 PM, Amanda Hemmerich wrote:

I did a search for this in the archive but didn't find anything.

Is there a way to preserve the format of text in a textbox that is being
saved in a database and then pulled out and displayed? The people
entering the data want to keep their tabs and newlines, but right now,
that's not happening.

Are you displaying the content back into a textarea, or into normal HTML?


<textarea>'s following basically the same rules as <pre>'s -- newlines and tabs will be respected, as long as your stylesheets don't override that.

My first suggestion is view the HTML source in a browser first, and see if the new lines are there in the source... If they aren't there, then they won't be there any other way.

If not, the white space (new lines, tabs, etc) must have been stripped out somewhere in your code on the way in or out of the database. Inserting them into the database should not remove white space by default, so if yours aren't there in the DB, then your code somewhere must be stripping it out.


However, if you just want to display the content and plain text on the HTML page, then you need to realise the following -- newlines, tabs and multiple spaces are ignored in most cases by HTML.


To preserve all the white space, you can put the text in a <pre> block, which respects white space formatting. You can also achieve the same thing with CSS elements. This is pretty much the only option for tabs, but I'd argue they aren't needed at all.

To preserve just newlines, you may consider something like nl2br(), which adds a <br /> tag to all newlines.


But this is all pretty much a HTML discussion, not PHP :)


Justin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to