title: PHP preg_replace &nbsp;
body: <p>I'm stuck with this one... </p>
  
  <p>I insert some data into a database table which comes from a form. Sometimes, this data contains html, so I do </p>
  
  <pre><code>$note = htmlentities(mysqli_real_escape_string($this-&gt;db, $_POST['note']));
  </code></pre>
  
  <p>I then store the $note in my database. When retrieving my notes, I check whether there is html code in it, and if there is, I want to have it highlighted using <code>highlight_string()</code>. That part works like a charm. Now here's the problem:</p>
  
  <p>I am displaying the highlighted string in a div container, but it's overflowing because the white spaces are being converted to <code>&amp;nbsp;</code>. I'm trying to remove those non-breaking spaces and replace them with a simple space so the highlighted string will be contained in the div.
  I have tried this so far:</p>
  
  <pre><code>$note = html_entity_decode($note);
  $note = highlight_string($note);
  $note = preg_replace('/&amp;nbsp;/', '', $note);  
  </code></pre>
  
  <p>I have also tried <code>$note = str_replace('&amp;nbsp;', ' ', $note);</code>, to no avail. </p>
  
  <p>Any help is very much appreciated! Thanks :)</p>