title: Why cant i combine javascript and php in my code?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-and-escape-newlines">Pass a PHP string to a Javascript variable (and escape newlines)</a>  </p>
  </blockquote>
  
  
  
  <p>I am quite new to the concepts of Javascript/jQuery and PHP. I have been using PHP implemented in Appserv for two weeks now to get data from a modbus device and store it in a csv file. Now i want to plot the data using jQplot. I am trying to write a simple program to first see if i can implement php and javascript code together in html. This is a code that i have written in html and uses both javascript and php. </p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Demo&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h2&gt;This is a script&lt;/h2&gt;
  &lt;script type="text/javascript"&gt;
      var out = &lt;?php echo "Hello"?&gt;;
      //var out = "Hello"
      document.write(out);
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When i run this code in the browser ( I use google chrome with windows 7) I only get the heading "This is a script". However if i remove the line with the php code and uncomment the next line</p>
  
  <pre><code>var out = "Hello";
  </code></pre>
  
  <p>then the code prints the output with "Hello" like its supposed to. Why is this?</p>