title: PHP parse html and change links
body: <p>I'm creating a proxy server with PHP, and i was wondering if it were possible to convert links (both relative and absolute) to absolute URLS and then change the links so that they go to a place on my website. Its hard to explain, but this is essentially what i want</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
   &lt;a href='http://www.google.com'&gt;This is a link&lt;/a&gt;&lt;br&gt;&lt;br&gt;
   &lt;a href='/index.php'&gt;This is another&lt;/a&gt;&lt;br&gt;
   &lt;form action='/act.php'&gt;
     &lt;input type='submit'&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Which i would get using </p>
  
  <pre><code>file_get_contents("http://www.thiswebsite.com")
  </code></pre>
  
  <p>The intended output would be</p>
  
  <pre><code>     &lt;html&gt;
  &lt;body&gt;
   &lt;a href='proxy.php?url=http://www.google.com'&gt;This is a link&lt;/a&gt;&lt;br&gt;&lt;br&gt;
   &lt;a href='proxy.php?url=http://www.thiswebsite.com/index.php'&gt;This is another&lt;/a&gt;&lt;br&gt;
   &lt;form action='proxy.php?url=http://www.thiswebsite.com/act.php'&gt;
     &lt;input type='submit'&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Thanks</p>