Jump to content

Archived

This topic is now archived and is closed to further replies.

wigwambam

Displaying data from MySQL

Recommended Posts

My 1st post.. hi everyone.

I have written a guestbook in PHP using MySQL. When I write the message to the database I use "mysql_real_escape_string" to convert the string.

This is my problem. When I display the info from the database (using echo) it does not display new lines.

e.g. someone signs guestbook with:

Hello,
My name is Fred,
Great site.

My output is:

Hello, My name is Fred, Great site.

How do I get the '\n or <br> chars in there?

Share this post


Link to post
Share on other sites
After you have pulled the string from the database but before you echo the string doing something like this:

$comment = str_replace("\n", "<br />", $comment);

Thats just guessing you are using something like comment for your variable, just change it to what ever you are using and it should work, let us know how you get on.

Share this post


Link to post
Share on other sites
or you could use nl2br
[code]
echo nl2br($comment);
[/code]

this converts all \n's to <br>'s

Share this post


Link to post
Share on other sites
great replies, thanks for your help. I knew there would be a simple solution, the hard part is finding the info - I'm currently converting from ASP to PHP and know where to ask in future, thanks again.

Share this post


Link to post
Share on other sites
You can easily find what you need in over at php.net which holds the fine and easy to follow manual too. First always check over at [a href=\"http://www.php.net/manual/en/\" target=\"_blank\"]http://www.php.net/manual/en/[/a] and have little browse through the manual to see if there is anythink there can help you.

If you cant find anythink then just post here and we will help!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.