file_put_contents with ampersand "&"
<p>I want to copy a file from a remote server to a local server via php. I'm not sure of the "best" approach to do this so I've tried a few different ways to accomplish this but I'm hitting roadblocks with those methods. </p>

<p>So I came up with a method using JSONP to (A) call the remote server and get the contents of the .php file and pass it back to the local server for the local script to then (B) call to a local php script and use file_put_contents to write the content to the local server. </p>

<p>All works fine UNTIL an ampersand is reached. The file write stops there.</p>

<hr>

<p>Edit to show data coming back. </p>

<pre><code>if ($mysqlErrorConnectServer || $mysqlErrorConnectDb || $mysqlErrorConfigTableMissing) {
    $errorMsg .= '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
                  . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;'
                  . '&lt;head&gt;'
                  . '&lt;title&gt;Example website &amp;copy; - Example description of example site&lt;/title&gt;'
                  . '&lt;style type="text/css"&gt;'
</code></pre>

<p>So if you look at the code coming back... there is a "&amp;copy" which needs to be there to display the copyright symbol on the page... but it stops the file_put_contents from writing the rest of the file. </p>
