title: How can I prevent str_replace from replacing twice in a row?
body: <p>I wasn't sure how to word this question properly, apologies. </p>
  
  <p>I'm trying to create clean virtual directories from names in a database. These names could be <code>foo bar</code>, <code>foo/bar</code>, <code>foo / bar</code>, <code>foo: bar</code> and so on.</p>
  
  <p>I'm trying to replace <code>spaces</code>, <code>:</code>, <code>/</code> with <code>-</code> to clean up the URLs so I have:</p>
  
  <pre><code>$search_array = array(" ","-", ":", "/");
  $clean_url = str_replace($search_array, "-", $name);
  </code></pre>
  
  <p>In the case of <code>foo bar</code>, this changes it to <code>foo-bar</code> which is my desired result, but when it comes to something like <code>foo : bar</code> it changes to <code>foo---bar</code></p>
  
  <p>Is there some way I can get str_replace to only replace once if multiple results are found?</p>
  
  <p>I thought about placing things such as <code>[space]:[space]</code> in the search array but I have about 600,000 names an am not sure of the amount of combinations there are.</p>