Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > <pre> and wordwrap

Reply
Thread Tools

<pre> and wordwrap

 
 
Christoph
Guest
Posts: n/a
 
      09-23-2006
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?

thnx,
Christoph


 
Reply With Quote
 
 
 
 
Toby Inkster
Guest
Posts: n/a
 
      09-23-2006
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-spacere-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wordwrap in agent news reader Kue2 Windows 64bit 5 06-30-2010 08:04 PM
GridView forcing wordwrap =?Utf-8?B?Z3V5?= ASP .Net 1 10-29-2007 03:18 PM
GridView without wordwrap Harvey Triana ASP .Net 0 04-03-2006 03:12 PM
table and wordwrap formatting Matt HTML 1 12-23-2004 07:01 AM
Wordwrap DataGrid Columns =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= ASP .Net 1 11-04-2004 04:41 AM



Advertisments