and wordwrap 

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a large amount of text that is getting pulled from a file.  It looks
something like this:

'large amount of text 90+ characters long

large amount of text 90+ characters long

large amount of text 90+ characters long'

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 on the
browser (due to where the text is positioned,  by necessity, on the page).
So is there something I can do, using CSS or anything else, that gives me
the best of both worlds?  That will (effectively) keep the CRLFs and also
wrap the text?


 and wordwrap 

Christoph wrote:

Quoted text here. Click to load it

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  ~

Site Timeline