title: PHP conditional string replacement str_replace
body: <p>This is the string i'm trying to replace white spaces <em>between the words</em> with "-".</p>
  
  <pre><code>$mystring = "Color red, Color blue, Color black";
  $newstring = str_replace(' ', '-', $mystring);
  </code></pre>
  
  <p>What i want to achieve, using the str_replace function, is:</p>
  
  <pre><code>"Color-red, Color-blue, Color-black";
  </code></pre>
  
  <p>But that returns:</p>
  
  <pre><code>"Color-red,-Color-blue,-Color-black";
  </code></pre>
  
  <p>I guess i need a condition that replaces white spaces "not after the comma" or "between two words".
  But i have no idea. Any suggestion?</p>