Jump to content

Format MySQL info?


CrazeD

Recommended Posts

How are you inserting it into your database table? Post the relevant parts of your code here.

 

If you enter

line1
line2
another line
b
l
a
h

It should go into the database as you have typed it.

 

However when you get the data back out of the database and display it in the browser you may find it displays as this:

line1line2another lineblah

This is nothing to do with PHP or MySQL but the browser itself. Web browsers ignore most whitespace characters (\n, \r, etc). In order for the browser to display your textareas you have entered it in the textarea you will need to use the html equivalent, eg <br /> for newlines.

Link to comment
https://forums.phpfreaks.com/topic/54272-format-mysql-info/#findComment-268756
Share on other sites

No no no, you're not listening.

 

It goes into the table as a one-line string, it doesn't have breaks in it.

 

I think you are the one not listening.

 

Anytime you enter data into a DB from a textarea it has \n characters or new line characters. www.php.net/nl2br converts the \n to < br />  so it is visible by the webbrowser.

 

I bet if you viewed the source of the data currently printed it would look like it did when you entered it into the DB.

 

Give it a try and see what happens.

Link to comment
https://forums.phpfreaks.com/topic/54272-format-mysql-info/#findComment-268764
Share on other sites

Archived

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

×
×
  • 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.