develooper Front page | perl.beginners | Postings from February 2002

Re: formatting database text

Thread Previous | Thread Next
Chas Owens
February 5, 2002 22:16
Re: formatting database text
Message ID:
On Tue, 2002-02-05 at 12:29, Hughes, Andrew wrote:
> I have created a news article database where non-technical people can cut
> and paste articles to be stored in a mySQL database table.  Everything
> works.  However when I display these in a browser, I want to have <p
> class="whatever"></p> tags around each paragraph, so that the non-technical
> people do not have to worry about adding these tags.  I was thinking the
> logic would go something like this:
> When displaying the body field of the database, before anything else print
> <p class="whatever">
> Then, for each blank line print </p><p class="whatever">
> Finally, after the last paragraph print </p>
> Should I do this when the articles go into or are pulled out of the
> database?
> How do I go about doing this?
> All suggestions are welcome.
> Thanks,
> Andrew
> -- 
> To unsubscribe, e-mail:
> For additional commands, e-mail:

You should really use <br /> instead of <p></p>, and consider using
something like (warning not tested):

<example type="untested">
$in_para = 0;
foreach (split '\n', $text) {
	if (/^\s*$/) { #if blank line or only white space
		if ($in_para) {
			$in_para = 0;
			print "</p>\n";
		print "<br />\n";
	} else {
		unless ($in_para) {
			$in_para = 1;
			print "<p>\n";
		print "$_\n";
print "</p>\n" if ($in_para);

Today is Boomtime the 37th day of Chaos in the YOLD 3168

Missle Address: 33:48:3.521N  84:23:34.786W

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About