|
Posted by Toby Inkster on 09/23/06 20:26
Christoph wrote:
> If I don't enclose the text in a <pre> tag, all the CRLFs are stripped and
> all the text runs together. If I do put it in a <pre> tag, the text goes
> off the right side of the screen and causes a scroll bar to appear
The CSS answer is "white-space:pre-wrap" which is in the CSS 2.1 draft,
but it's not widely supported by browsers.
The alternative is to use server-side scripting to format the text
appropriately. There are two ways to do this:
1. Use PHP's wordwrap() function (or an equiv function in another
language) to ensure that no lines are too long, before dumping it
all into a <pre>...</pre> block; or
2. Use PHP's nl2br() function (or equiv) to convert the existing
line breaks into <br> tags, then dump the whole thing into a
<div>...</div> block.
The second solution is probably a better idea, because it allows the
browser to do its own word wrapping. The browser will almost certainly do
a better job at wrapping than the server would have.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|