Jump to content

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?

Link to comment
https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/
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.
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!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.