str_replace() works on WampServer but not on live server?
<p>I have a function which builds a multi-line string that needs to be echo'd out as a JavaScript variable, so after the string is built I run it through <code>str_replace()</code> before returning it like this:</p>

<pre><code>return str_replace("\r\n", "\\\r\n", $output);
</code></pre>

<p>Here's the weird thing: this works fine on my development machine running WampServer, but it doesn't add the slashes at the ends of the lines on my live server (VPS running Apache and the latest version of PHP).</p>

<p>Example:</p>

<pre><code>return (str_replace("\r\n", "\\\r\n",
        'this
        is
        a
        test'));
</code></pre>

<p>Dev. machine:</p>

<pre><code>this\ is\ a\ test 
</code></pre>

<p>Live server:</p>

<pre><code>this is a test
</code></pre>

<p><br>
I've been looking through the documentation, but have no idea why this is happening. Any ideas?</p>

<p><strong>Solution:</strong></p>

<pre><code>return (str_replace(PHP_EOL, '\\' . PHP_EOL,
        'this
        is
        a
        test'));
</code></pre>
