title: JavaScript script tag inside php code
body: <p>I have one page (parent) which opens a second page via popup (child)</p>
  
  <p>On the second page I have the following PHP code which gets the value of an HTML element from the parent page:</p>
  
  <pre><code> $var=print_r("&lt;script type='text/javascript'&gt;var x=window.opener.document.getElementsByName('name1');document.write(x[0].value)&lt;/script&gt;",true);   
  </code></pre>
  
  <p>When I echo the variable <code>$var</code> I get exactly what I expect. Thus:</p>
  
  <pre><code>echo "test=" . $test;
  </code></pre>
  
  <p>... prints for example "Expenses" on the page.</p>
  
  <p>So far so good.</p>
  
  <p>The problem is when I try to write this variable to a file like:</p>
  
  <pre><code>$f=fopen("/mylog.txt","w+");
  fwrite($f, $test);
  fclose($f);
  </code></pre>
  
  <p>... then , instead of the actual value of <code>$test</code> (e.g. Expenses),</p>
  
  <p>I get the whole script tag in my logfile, thus:</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;var x=window.opener.document.getElementsByName('name1');document.write(x[0].value)&lt;/script&gt;
  </code></pre>
  
  <p>Assuming that <code>print_r</code> with 'true' parameter returns the value to my <code>$test</code> variable, why is it writing the exact script tag to the logfile?</p>
  
  <p>How can I overcome this?</p>