title: PHP - display remote page's content in full
body: <p>I need to fetch a remote page, modify some elements (using 'PHP Simple HTML DOM Parser' library for that) and output modified content.</p>
  
  <p>There's a problem with remote pages that don't have full URLs in their source, so CSS elements and images are not loaded. Sure, it doesn't stop me from modifying elements, but the output looks bad.</p>
  
  <p>For example, open <a href="https://www.raspberrypi.org/downloads/" rel="nofollow noreferrer">https://www.raspberrypi.org/downloads/</a></p>
  
  <p>However, if you use code </p>
  
  <pre><code>$html = file_get_html('http://www.raspberrypi.org/downloads');
  echo $html;
  </code></pre>
  
  <p>it will look bad. I tried to apply a simple hack, but that helps just a little:</p>
  
  <pre><code>$html = file_get_html('http://www.raspberrypi.org/downloads');
  $html=str_ireplace("&lt;/head&gt;", "&lt;base href='http://www.raspberrypi.org'&gt;&lt;/head&gt;", $html);
  echo $html;
  </code></pre>
  
  <p>Is there any way to "instruct" script to parse all links from $html variable from '<a href="http://www.raspberrypi.org" rel="nofollow noreferrer">http://www.raspberrypi.org</a>'? In other words, how to make raspberrypi.org to be the "main" source of all images/CSS elements fetched?</p>
  
  <p>I daon't know how to explain it better, but I believe you got an idea.</p>