You are here: Re: Preformatted text with wrap « HTML « IT news, forums, messages
Re: Preformatted text with wrap

Posted by Joseph Misko on 11/20/18 11:19

A great idea, the last one. All three actually, and the only workable
suggestions I have received from a few different groups. I will give the
str_replace a whirl.

Thanks,
Joe

"Toby Inkster" <usenet200506@tobyinkster.co.uk> wrote in message
news:pan.2005.06.22.07.21.37.991416@tobyinkster.co.uk...
> Joseph Misko wrote:
>
>> 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:pre-wrap" property of CSS 2.1:
>
> <pre style="white-space:pre-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.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> Contact Me ~ http://tobyinkster.co.uk/contact
>

 

Navigation:

[Reply to this 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

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