wigwambam Posted March 27, 2006 Share Posted March 27, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/ Share on other sites More sharing options...
Eddyon Posted March 27, 2006 Share Posted March 27, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/#findComment-21382 Share on other sites More sharing options...
earl_dc10 Posted March 28, 2006 Share Posted March 28, 2006 or you could use nl2br[code]echo nl2br($comment);[/code]this converts all \n's to <br>'s Quote Link to comment https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/#findComment-21391 Share on other sites More sharing options...
wigwambam Posted March 28, 2006 Author Share Posted March 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/#findComment-21481 Share on other sites More sharing options...
wildteen88 Posted March 28, 2006 Share Posted March 28, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/5967-displaying-data-from-mysql/#findComment-21495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.