in reply to Formatting paragraph

What about:
# First encode possible HTML, because the text is # supposed to be plain text use HTML::Entities(); $text = HTML::Entities::encode($text); # Convert Windows or Mac line terminators to Unix single \n $text =~ s/\r\n|\n\r/\n/g; # Remove leading and trailing white space $text =~ s/^\s*//; $text =~ s/\s*$//g # Convert all double line breaks to para tags $text =~ s|\n\s*\n|</p><p>|g # Convert any single line breaks to br tags $text =~ s|\n\s*|<br />|g # If text is more than just white space, add opening and # closing para tags $text = "<p>$text</p>" if $text;

Replies are listed 'Best First'.
Re^2: Formatting paragraph
by Anonymous Monk on Feb 03, 2006 at 01:17 UTC
    I'm sorry but how was my question OT? I'm pretty sure Perl is required to do what I'm doing. is it not? The two replies all had to do with Perl and html, so in the end its still on topic since it deals with Perl.

      Yes, the significative replies you got all have to do with Perl and HTML. The question, though, had to do with neither. Actually no perl code is shown nor Perl is mentioned at all, although being here suggests beyond any reasonable doubt that you're using perl to get your data out of the db. OTOH no mention at all is being made of HTML either. People made a reasonable guess, and it turned out to be correct. Due to my cultural backround -or lack of imagination- it was not just as easy for me to get at the same guess. So yes: your question had to do with Perl, but it was about "formatting pure text for display in a web page". Or something that. Wasn't it?