title: How to store formatted text in MySQL table?
body: <p><strong>[My EDITED New Question]</strong></p>
  
  <p>I am taking text input in HTML form as <code>&lt;textarea&gt;</code>. Suppose the user entered the following text:</p>
  
  <pre><code>1. Hello     World
  2. Hi World
  
  3. Hola
  </code></pre>
  
  <p>My PHP code is inserting into the table as: <code>1. Hello World\r\n2. Hi World\r\n\r\n3. Hola</code></p>
  
  <p>I am displaying this text into a DIV element by using the below method (assume that <code>$text</code> is retrieved from database):</p>
  
  <p><code>&lt;div&gt;&lt;?php echo $text ?&gt;&lt;/div&gt;</code></p>
  
  <p>The output I am getting is: <code>1. Hello World 2. Hi World 3. Hola</code></p>
  
  <p>How to get the exact output as user entered? Only importance to me right now is spaces, tabs and new line characters. As mentioned in the below answers, <code>nl2br()</code> is not suggested. Any other way?</p>
  
  <hr>
  
  <p><strong>[My Old Question]</strong>
  I want to store formatted text into a mysql table. By formatted, I mean to preserve proper bold characters, italics, underline, spaces, tabs, punctuation marks, newline characters etc. </p>
  
  <p>If the above is not possible, if I can preserve the following formatting then also my requirement is fulfilled:</p>
  
  <ol>
  <li>spaces and tabs </li>
  <li>punctuation marks and newline characters</li>
  </ol>
  
  <p>Is there any data type which can store such data? What about VARCHAR, TEXT and CHAR data types? Please help!</p>
  
  <p>For example: If I type the following text:</p>
  
  <pre><code>Hi!
  
  Hello there!
  </code></pre>
  
  <p>then it should NOT print like </p>
  
  <pre><code>Hi! Hello there!
  </code></pre>