title: Getting linebreaks stored as \n in database to print out with PHP
body: <p>I imported a CSV into a database I am testing some things with (very new to SQL). While importing I had some trouble with some text fields in a <code>msg</code> column which contained linebreaks (phpMyAdmin thought they were new rows I think) so I had to convert all the linebreaks in those columns to \n in the CSV. The importer worked fine after that.</p>
  
  <p>As such I have some text fields in the database which are stored like this:</p>
  
  <p><code>Here is an example\nof a field\nwith line breaks</code></p>
  
  <p>I am now trying to get these fields to print out on a simple PHP page (very new to this as I said)!</p>
  
  <p>Initially I tried:</p>
  
  <pre><code>...
  while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC) ) {
      ...
      echo $row['msg'];
      ...
  }
  ...
  </code></pre>
  
  <p>This prints out most fields in my database fine but the ones that contain <code>\n</code> are not showing with linebreaks, they're literally just printing out the <code>\n</code> as part of the string.</p>
  
  <p>I did some research and tried using the <code>nl2br();</code> PHP function:</p>
  
  <pre><code>// If I input a string it works fine and outputs &lt;br /&gt; tags
  echo nl2br("Here is an example\nof a field\nwith line breaks");
  
  // But when working with the database fields it still doesn't work.
  echo nl2br($row['msg']);
  </code></pre>
  
  <ol>
  <li><p>If anyone could help me to get the linebreaks to print out I would be really grateful.</p></li>
  <li><p>I appreciate I am very new to databases and perhaps there is something fundamentally wrong with the way I am processing the data? So likewise if anyone has any suggestions on how I could improve things I'd be really grateful. I'm not sure if <code>nl2br();</code> is what I should be using here.</p></li>
  </ol>