title: What's the best way to keep line breaks from a form entry to mysql and handle mysql escapes
body: <p>I have a question I have been pondering for a while.</p>
  
  <p>What is the best way of keeping line breaks to a MySQL db and handle the escapes so that the query doesn't fail.</p>
  
  <p>I came up with a function to do this but I am not sure this is the right way to handle the string.</p>
  
  <pre><code>function nl2br2 ($string){
      $sqlescapes = array("'", ";");
      $string = str_replace($sqlescapes, "", $string); 
      return str_replace( "\n", '&lt;br /&gt;', $string ); 
  }
  </code></pre>
  
  <p>This function will replace PHP line breaks and replace them with <code>&lt;br/&gt;</code> so html can recognise them if I use mysqli_real_escape_string it removes the line break and this is the predicament.</p>
  
  <p>Are there any other functions I could utilise, as the above removes grammar from the string?</p>