in reply to Formatting paragraph

You need to convert it from plain text to HTML. The following is a start:
foreach ($text) { s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/\n/<br>/g; }

It's not perfect. For example, it won't stop the browser from collapsing multiple spaces into one. For that, you'd have to use something like the following:

foreach ($text) { s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; $_ = "<pre>$_</pre>"; }

You have to restrict yourself to monospace fonts (like Courier New) for <pre> to work properly (but <pre> text should default to a monospace font).

Replies are listed 'Best First'.
Re^2: Formatting paragraph
by pKai (Priest) on Feb 02, 2006 at 17:03 UTC
    How could I have it so it displays properly with line breaks.
    You need to convert it from plain text to HTML

    I wonder how the OP was able to deliver his SoPW post -- completely well-formatted, making his point -- without being HTML aware?

Re^2: Formatting paragraph
by blazar (Canon) on Feb 02, 2006 at 12:15 UTC
    You need to convert it from plain text to HTML.

    Gosh! I was having a hard time trying to make sense of the OP's request when I read your reply: I keep forgetting that most often here people asks about web development without even clearly saying so...

      The amazing thing is that he posted a completly off topic node, and NOBODY flamed him.

      This is not your standard news group!

        Heh. Some years ago, Dilbert and Wally were apparently engaged in an e-mail argument, and Wally remarked to Dilbert: "You're might brave in cyber-space, Flame-boy!" (I wish I could find a linkable copy of the comic.) I think a lot of news group participants post remarks that they would never say in person.

        One of the beauties of PerlMonks is that people are 'accountable' via XP for what they say, here. In spite of the fact that XP is "an imaginary number given to you by a stranger", I find it serves as a powerful motivator to word my posts more carefully. The preview feature helps a lot, too.

        In most news groups, you post a message and you never really know what most people thought of it. You may get a few responses from those who strongly agree or disagree with you, but you miss out on the non-verbal cues (like the people who would roll their eyes or look away if you said the same thing in person). Many people can't be bothered to reply unless they feel strongly. At PerlMonks, you can know within a few minutes if your posting was perceived positively or negatively -- after a few downvotes, you learn to be careful.

        Personally, I really like the higher standard, which is why I stick around (apart from the fact that being a PerlMonk is a powerful chick-magnet). I've been practicing my pick-up lines:

        • Hey, baby, what's your level?
        • Wanna go back to my place and check out my obfuscations?

        My wife just laughs at me whenever I talk about PerlMonks. Happily, she married me in the first place because I made her laugh, although she managed to keep a straight face when I actually proposed. :)


        No good deed goes unpunished. -- (attributed to) Oscar Wilde