Reply to Re: <pre> and wordwrap

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация