0

A little bit of background (you can skip this): I'm trying to create a simple proxy using PHP. All I am doing right now is using file() on a URL string and echoing everything with a foreach loop (if you really want to see it, it's here).

Anyway, I have a string of HTML that I need to fix so that no URLs on the page are local. In that, all HTML code that refers to locations like "/dir/file.ext" need to refer to "http://example.com/dir/file.ext". I have looked at DOMDocument and Tidy, but I'm not so sure how I'm going to go about this. Any ideas?

...I did consider setting up RewriteEngine attributes in my .htaccess file, but it seemed that might not catch all instances - or would it?

Hayden Schiff
  • 3,280
  • 19
  • 41
  • Look into `file_get_contents()` and just injecting a ``. You'll run into more problems down the road, as you are not really building a proxy. – mario Oct 13 '11 at 01:25
  • Wow I completely forgot about the tag in HTML. However, just using does cause a problem where non-HTML code (JavaScript and whatnot) will break. Is there a way to do this that will cover more potential problems? EDIT: I see what you're saying about me not really building a proxy, since my current code only works for plain documents, but couldn't I just get the file extension from the URL and use header() to inform the browser? – Hayden Schiff Oct 13 '11 at 01:32
  • possible duplicate of [Find IPs in a text file and convert them to URL](http://stackoverflow.com/questions/19367408/find-ips-in-a-text-file-and-convert-them-to-url) – Paul Sweatte Nov 15 '13 at 02:31

0 Answers0