Joseph said:
I am using MySQL to serve plain text email newsletters using PHP. I have
the text of the emails stored, and I thought the <pre> tag would be my
answer. However, that doesn't break at the page width. Basically, I need a
tag or option that allows me to keep the paragraph and linebreak formatting,
but will wrap and not produce lines a thousand characters long.
There are two solutions -- client-side and server-side. Neither are ideal
though and a better solution would be to avoid the use of <pre> for this
purpose.
Client-side - use the "white-space

re-wrap" property of CSS 2.1:
<pre style="white-space

re-wrap">
This is some preformatted text, but very long lines will be wrapped
automatically.
</pre>
Drawback of "pre-wrap" is that several browsers, including Internet
Explorer, don't support it. D'oh!
Server-side - use PHP's "wordwrap()" function:
<pre><?php print wordwrap($mytext, 72) ?></pre>
Drawback here is it will wordwrap your text at (in the example above) 72
characters, no matter how wide or narrow the visitor's screen is. D'oh
again! Also, it's not supported in PHP before 4.0.2.
A better idea might be to avoid using <pre> altogether. For example:
<?php
$mytext = function_to_get_it_from_database();
$mytext = htmlspecialchars($mytext);
$mytext = str_replace("\r\n", "\n", $mytext);
$mytext = str_replace("\n\n", '</p><p>', $mytext);
$mytext = str_replace("\n", '<br>', $mytext);
print "<p>${mytext}</p>";
?>
might do the job for you.