This is extremely nontrivial. I recommend that you find a tool that will do it for you, rather than trying to write a PHP app to do it.
It requires capturing external objects (images, css etc), saving them into local filenames, which may need to be changed from the remote server, and modifying all the HTML accordingly to point to local versions of these items.
There are some apps which can do that. I recommend you find one, rather than trying to make your own - you will probably not succeed very well if you try (it requires a LARGE amount of work - there are a lot of different syntaxes for including external objects; relative URLs are tricky to work out. It has to deal (as best it can)with incorrect HTML as well).
If you were to write such a tool yourself, you'd need to account for:
- Images
- Scripts
- Frames
- Iframes
- CSS
- Stylesheet includes
- Inline stylesheet includes
- Handling redirects correctly
- Handling relative and absolute URLs correctly (root-relative as well as absolute ones)
Plus probably lots of other things I can't think of right now.
You still wouldn't be able to detect and capture any resources that were referenced programmatically by Javascript.
Firefox has a feature "save web page as..." which takes all the dependent resources and saves them out too (optionally). I think MSIE also has something "Make available offline" which does something similar.
Mark