title: how to load properly sql data with a new line
body: <p>im trying to query my database and when im using the code below, it repeats some part of the data</p>
  
  <pre><code>$data = $result['testdata'];
  $data = str_replace("\r\n", "&lt;br&gt;", $data);
  $data = str_replace("\r", "&lt;br&gt;", $data);
  $data = str_replace("\n", "&lt;br&gt;", $data);
  
  echo "&lt;form action='testsearch.php' method='post'&gt;";
  
  echo"&lt;tr&gt;"; 
  echo  "&lt;td align='center' width='auto'&gt;" . $result['test'] . "&lt;input type=hidden name=test value=" . $result['test'] . "' /&gt; &lt;/td&gt;";
  echo  "&lt;td align='left' width='500'&gt;" . $data . "&lt;input type=hidden name=testdata value=" . $data . "' /&gt; &lt;/td&gt;";
  "&lt;/tr&gt;"; 
  </code></pre>
  
  <p>here is the snapshot of the result of the code above:</p>
  
  <p><img src="https://i.stack.imgur.com/5CTRI.jpg" alt="Code1"></p>
  
  <p>now when i try to use <code>htmlentities</code> in the code to resolve the issue im losing the new line and being replace instead by <code>&lt;br&gt;</code></p>
  
  <pre><code>$data = $result['testdata'];
  $data = str_replace("\r\n", "&lt;br&gt;", $data);
  $data = str_replace("\r", "&lt;br&gt;", $data);
  $data = str_replace("\n", "&lt;br&gt;", $data);
  $data1 = htmlentities($data);
  
  echo "&lt;form action='testsearch.php' method='post'&gt;";
  
  echo"&lt;tr&gt;"; 
  echo  "&lt;td align='center' width='auto'&gt;" . $result['test'] . "&lt;input type=hidden name=test value=" . $result['test'] . "' /&gt; &lt;/td&gt;";
  echo  "&lt;td align='left' width='500'&gt;" . $data1 . "&lt;input type=hidden name=data1 value=" . $data1 . "' /&gt; &lt;/td&gt;";
  "&lt;/tr&gt;"; 
  </code></pre>
  
  <p>here is the snapshot of the second code:</p>
  
  <p><img src="https://i.stack.imgur.com/1diO2.jpg" alt="Code2"></p>
  
  <p>i need help in maintaining the new line and at the same time not repeating the datas fetch from mysql db...</p>