title: PHP - Escape dollar sign
body: <p>How can I modify a string to ensure that the dollar sign is preceded by an odd number of backslashes?</p>
  
  <pre><code>&lt;?php
    $string = file_get_contents('somefile.txt');
    echo($string."\n");
    $string=str_replace ('$' , '\$' ,$string);
    echo($string."\n");
   ?&gt;
  </code></pre>
  
  <p>somefile.txt</p>
  
  <pre><code>$first
  \$second
  \\$third
  \\\$forth
  \\\\$fifth
  </code></pre>
  
  <p>OUTPUT</p>
  
  <pre><code>    $first
  \$second
  \\$third
  \\\$forth
  \\\\$fifth
  \$first
  \\$second
  \\\$third
  \\\\$forth
  \\\\\$fifth
  </code></pre>