title: How to provide dynamic HTML in PHP?
body: <p>I've got a HTML file which I've created and is stored in a directory elsewhere.</p>
  
  <p>The problem is, I'd like to be able to get content externally and place it within the HTML file.</p>
  
  <p>I figured I could use PHP for this, because it's server-side and can access the files I want.</p>
  
  <p>So, I created a PHP script which opens and echoes a HTML file, and afterwards, echos some JavaScript to change elements that are on the screen.</p>
  
  <p>Here's my PHP file:</p>
  
  <pre><code>&lt;?php
  
  $html = file_get_contents('file.html');
  
  $imageurl = file_get_contents('url.txt');
  
  $js = '&lt;script type=\'text/javascript\'&gt;updateImage(\'img1\', '.$imageurl.');&lt;/script&gt;';
  
  echo $html;
  
  echo $js;
  
  ?&gt;
  </code></pre>
  
  <p>..and the HTML file:</p>
  
  <pre><code>&lt;html&gt;
  &lt;script type="text/javascript"&gt;
  function updateImage(id, url) {
      var img = document.getElementsByName(id)[0];
      img.src = url;
  }
  &lt;/script&gt;
  
  &lt;body&gt;
  
  &lt;img src="" name="img1" /&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>It's not the best method, but it works.</p>
  
  <p>I would like to know a way to do this within PHP, not using JavaScript.</p>
  
  <p>I'm not sure as of the best approach to this.</p>