title: How to REPLACE \n with <br> in PHP
body: <p>I've tried <a href="http://php.net/manual/en/function.nl2br.php" rel="nofollow noreferrer"><code>nl2br()</code></a> as well as ALL of the methods listed in the comments <a href="http://php.net/manual/en/function.nl2br.php" rel="nofollow noreferrer">here</a>. The problem I have is that even though they do insert the <code>&lt;br/&gt;</code>, the <code>\n</code> still remains in the text.</p>
  
  <p>This is what I was originally doing:</p>
  
  <pre><code>&lt;?php
  
  $stmt = $db-&gt;prepare(...)
  
  $stmt-&gt;execute();
  
  while ($row = $stmt-&gt;fetch()) {
  
      $tldr_clean = nl2br($row['tldr']);
      $body_clean = nl2br($row['body']);
  
      ?&gt;
  
      &lt;section&gt;
  
          &lt;h2 class="tldr"&gt;&lt;?= $tldr_clean ?&gt; &lt;?= $row['score']?&gt;/10&lt;/h2&gt;
  
          &lt;p class="body"&gt;&lt;?= $body_clean ?&gt;&lt;/p&gt;
  
          &lt;p class="reviewer"&gt;Written by &lt;?= $row['name'] ?&gt;&lt;/p&gt;
  
      &lt;/section&gt;
  
  &lt;?php
  } ?&gt;
  </code></pre>
  
  <p>Assuming <code>$row['body']</code> is <code>"Hello\nGoodbye"</code>, the output in the html is:</p>
  
  <pre><code>Hello\n
  Goodbye
  </code></pre>
  
  <p>I've tried using the method <code>nl2br()</code> directly with the string that is stored in the database, <strong>and it works correctly</strong>. So I'm guessing the problem is in calling the method with a variable? How can I fix it?</p>
  
  <p>Edit:</p>
  
  <p>String is stored as NVARCHAR2 in an SQLite table.</p>
  
  <p>String stored in database:</p>
  
  <p>"Fusce vitae purus tristique, efficitur dolor et, tristique ante. Aliquam sapien nisl, sagittis id justo eget, placerat ultrices nisl. In tempus sollicitudin mauris ut feugiat. Pellentesque imperdiet risus at ex dictum, sed tempus est pulvinar. Nunc nec leo fringilla diam sodales euismod sed sed odio.\n
  Cras mollis, quam at iaculis semper, justo dui maximus tellus, quis dictum urna velit sit amet justo. Curabitur consectetur fringilla arcu, sit amet ultrices est dignissim eget. Etiam non dapibus justo, et semper quam. Suspendisse tristique augue sit amet gravida euismod. Ut tempus metus quis nisl sagittis volutpat. Nam rhoncus diam luctus dictum tristique."</p>