webref.eu Posted March 20, 2009 Share Posted March 20, 2009 Hi All I am displaying data from MySQL, but the linebreaks aren't being recognised. When I look in MySQL Query Browser there appear to be the linebreak characters there, but when I pull the data from the db and display on a page in the browser, the linebreaks are only whitespace, so the data is displayed continuously without linebreaks. How do I get the linebreaks to be shown properly on the page? Thanks All Link to comment https://forums.phpfreaks.com/topic/150351-how-to-get-linebreaks-when-displaying-data-from-db/ Share on other sites More sharing options...
Maq Posted March 20, 2009 Share Posted March 20, 2009 Should be regular tags. Can we see a sample of your code and how you're displaying it? Link to comment https://forums.phpfreaks.com/topic/150351-how-to-get-linebreaks-when-displaying-data-from-db/#findComment-789603 Share on other sites More sharing options...
webref.eu Posted March 20, 2009 Author Share Posted March 20, 2009 Some snippets from the code: Getting the data: while ($list = mysql_fetch_assoc($result)) ... Displaying the data: $list['ReviewDesc'] I've just found that by using the nl2br function as below I can get linebreaks to be rendered in the browser, so I assume this is the best way of doing it? nl2br($list['ReviewDesc']) Rgds Link to comment https://forums.phpfreaks.com/topic/150351-how-to-get-linebreaks-when-displaying-data-from-db/#findComment-789615 Share on other sites More sharing options...
wildteen88 Posted March 20, 2009 Share Posted March 20, 2009 I've just found that by using the nl2br function as below I can get linebreaks to be rendered in the browser, so I assume this is the best way of doing it? nl2br($list['ReviewDesc']) Rgds Yes that is the only way. Web browsers ignore whitespace characters. nl2br converts new lines to a HTML line break tag <br />. Link to comment https://forums.phpfreaks.com/topic/150351-how-to-get-linebreaks-when-displaying-data-from-db/#findComment-789707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.