 <p>This should work (without a double replace):</p> <pre><code>&lt;? echo preg_replace("#(http|ftp|https):/([^/])#", "$1://$2", 'http://www.google.com'); echo "&lt;br&gt;"; echo preg_replace("#(http|ftp|https):/([^/])#", "$1://$2", 'http:/www.google.com'); ?&gt; </code></pre> <p>This will only do the replace if there is no double slash.</p>