How to remove duplicate slashes from file path
<p>This question HAS been asked before and got closed WITHOUT any answers</p>

<p>Second time lucky, my previous question got closed: <a href="http://stackoverflow.com/questions/14903375/php-clean-up-path-with-duplicate-slashes">php clean up path with duplicate slashes</a> looks like I was missing the question mark to make it obvious what my question was. </p>

<p>QUESTION:</p>

<ol>
<li>How can I remove the duplicate slashes from a string? See code below with examples.</li>
<li>How well does windows(wamp) support file paths using forward slashes? It feels wrong writing c:/wamp but appears to work fine as the reason why I am unsure.</li>
</ol>

<p>CODE:</p>

<pre><code>&lt;?php
function clean($full_path){
    return str_replace(array("\\", "//", "\/", "/\"), DIRECTORY_SEPARATOR, $full_path);
}

$paths = array(
 'var/www/tpl//main.tpl',
 'C:\wamp\www\/tpl\\main.tpl',
 'C:\wamp\www/\tpl\main.tpl');

 foreach($paths as $path){
     echo "Before: $url\nAfter:  ".clean($path)."\n---------------------\n";
 }
 ?&gt;
</code></pre>
