Jump to content

Recommended Posts

use the nl2br() function to change the strings \n to the br tag. here is an example.

 

$string = "This is a string with a \n newline in it."; //newline string.
$string = nl2br($string);

echo $string; //The string will now be properly formatted

Link to comment
https://forums.phpfreaks.com/topic/40318-n-does-not-work/#findComment-195062
Share on other sites

To be safe, I would use mysql_real_escape_string() before inserting the data to mysql.  Then you can be sure that ANY character will be correctly stored (any that is supported by the underlying data type that is.  Binary data will need mysql's binary data type, which I forgot the name of.  But \n is still ok for text/varchar data).

Link to comment
https://forums.phpfreaks.com/topic/40318-n-does-not-work/#findComment-195088
Share on other sites

no mater what  OS you use MySQL will store the the newline. It just when you send newline charactersw (\r\n, \r or \n) to a web browser it will just ignore them - They are still there but can only be viewed from source. In order to get the browser to display them you need to use the HTML line breaks (<br />).

 

It best to use nl2br when getting data out of the database, not when inserting it into the database.

Link to comment
https://forums.phpfreaks.com/topic/40318-n-does-not-work/#findComment-195399
Share on other sites

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.