Jump to content

Recommended Posts

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

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

 

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 />.

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.