title: How to skip specific line preg_replace - PHP
body: <p>I made a small function that is removing extra whitespace from strings </p>
  
  <pre><code>/* remove white space */
  function wspace($string){
  
      $string = preg_replace( '/\s+/', ' ', $string);
      return $string;
  }
  </code></pre>
  
  <p>it works nice but the issue I have is following; 
  if I am using this function on js strings wich is intended , the lines that have commments like </p>
  
  <pre><code>// will brake js output, 
  </code></pre>
  
  <p>Example </p>
  
  <pre><code>      $js_string .="
          window.addEvent('load', function(){
              new Drop({
                  container:'container',
                  offset: ".$offset.", // top menu offset
                  width:200
              });
          });
        ";
  
  echo wspace( $js_string );
  </code></pre>
  
  <p>this will output </p>
  
  <pre><code>window.addEvent('load', function(){ new Drop({ container:'container',offset: ".$offset.", // top menu offset width:200 }); });";
  </code></pre>
  
  <p>which is commenting out everything after <code>//</code> </p>
  
  <p>how would I go about skipping or replacing those lines with <code>/*</code> or anything that would not mess-up the rest of the code? </p>
  
  <p>I know that replacing <code>//</code> with <code>/*</code> comment <code>*/</code>  is what should be done, but I am making update on my old script that is widely used and I don't know if users have <code>//</code> or /<code>*</code> comment <code>*/</code> . So in order to not break someone's code I need to be certain before I release this. </p>
  
  <p>I would like to do something like 
  </p>
  
  <pre><code>if($string contains // ) skip to next line 
  </code></pre>
  
  <p>or anything that you think it would work to make this function more secure. </p>
  
  <p>Any help is appreciated. Thank you! </p>