title: how to write php code to a file with php
body: <p>For part of my website I need to be able to write php code to a file with php.
  For example:</p>
  
  <pre><code>$filename = "RtestR.php";
  $ourFileName =$filename;
  $ourFileHandle = fopen($ourFileName, 'w');
  
  
  
  $written =  "
      &lt;html&gt;
      &lt;body&gt;
      &lt;?php
      echo \"I like the color \".$_SESSION['color'].\"!!!!\";
      &lt;/body&gt;
      &lt;/html&gt;
  
  ";
  
  fwrite($ourFileHandle,$written);
  
  fclose($ourFileHandle);
  </code></pre>
  
  <p>But, instead of creating the file, it throws this error:</p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 14</p>
  </blockquote>
  
  <p>What am I doing wrong and what is the right way to write php code to a file?
  <br/>EDIT:<br/>I think I might need to make myself clearer... I want the SESSION to be determined when the newly created file is loaded. Technically I don't want to get the session on this page, but instead on the page I am creating!!! I want to write the <strong>code</strong> to the file, not the output of the code! </p>