Re: formating text retrieved from a db

From: Polar (polarj_at_shaw.ca)
Date: 06/20/04


Date: Sat, 19 Jun 2004 22:22:09 GMT


"Andy Barfield" <abarfield_01@yahoo.com> wrote in message
news:40d4a95e$0$6321$65c69314@mercury.nildram.net...
> Polar wrote:
> > Telling me to RTFM is not the way I expected help.. I read the manual. I
> > tried. Thought I would get a different approach posting my code.. but
thats
> > okay I'll find another way.
>
> Another poster explained it for you -
> <quote>
> That's the way plain text is displayed within HTML. You had to add HTML
> tags. You may find nl2br() useful.
> </quote>
>
> If you were to display a phrase in your browser in simple HTML, such as:
> <p>Hello World
> how are you today?</p>
>
> Your browser would display:
> Hello World how are you today?
>
> Theis is because your browser will treat consecutive whitespace as just
> one whitespace character.
>
> So in basic HTML you create your code something like:
> <p>Hello World<br />
> how are you today?</p>
>
> ...and that would display as you expected it to (the <br /> creates a
> line break).
>
> In PHP, you would use something like nl2br($row['comment_field']); which
> replaces all new line characters (\n) with line break characters <br />
>
> I think that this is explained in the manual, hence the other poster's
> advice.
>
> regards,
>
> Andy
>

Thanks Andy .. that all is in the manual. I see that and I can do the
simple text messages if I hardcode them... my problems is I am pulling the
text for a cell of the database. I apprecieate the time you take wth me.. I
think I've gotten along fine for only starting php coding 2 weeks ago.
Last time I tried coding something was 1993 in C++ ( I think ;) ) It's
been awhile.

with my code I can pull out the name title etc and put them in the HTML
table fine. but when I put the nl2br() around the $row[5] of the query it
just brings back the text on mass with nl2br() around it.

 the story text output looks like this...

nl2br(Far beyond the purple haze of the distant ridge, hidden from view to
the naked eye, lay a range of mountains. They have a lofty name, a lofty
reputation and a lofty attitude. But, on every clear day, they effect his
life in a way not too many other things could. He met someone there, once. A
fleeting moment. A butterflies kiss in a lifetime, but a moment as strong at
the mountains, and as lasting. Each clear day he runs the gauntlet of his
emotions. He pauses. He watches. He remembers. A tune on the radio plays
sweetly in the background.... )

the part of the script looks like this.

// Fetch and print the record.
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td align=\"left\" width=\"25\">$row[0]</td><td align=\"left\"
width=\"75\">$row[1]</td><td align=\"left\" width=\"250\">$row[2]</td><td
align=\"left\" width=\"50\">$row[3]</td><td align=\"left\"
width=\"50\">$row[4]</td></tr></span><tr><td colspan=\"5\"
width=\"500\">nl2br($row[5])</td></tr>\n";
}
echo '</table>';
echo '<hr>';

Now in the Database if I look at it with phpMyAdmin I see the text... it
has the formating with blank lines between the paragraphs etc. there is no
/n codes I see. If I manually put in <P> in front of all the paragraphs in
the db then my script shows the text all formatted fine. But I don't want
to go in and manually edit stories with 100 paragraghs..

Your ideas are most welcome.

Polar :)