views:

524

answers:

5

I need to write a script that goes to a page, copies the source of the page, and stores it as a string to be outputted withing another page. I'm forced to do this due to the fact that the target page is dynamic, and apparently we need static records of that page within our internal system.

I know a limited amount of php. Can anyone point me in the right direction?

+5  A: 

cUrl is precisely what you need. Here's a basic tutorial: http://www.tellinya.com/read/2007/06/05/12.html (although the blog suggests that you check the new post, that article shows the raw functions of cUrl instead of a pre-made class)

With it, you can access http pages, make POST queries, etc. Pretty much everything you could do with a brwoser.

Daniel S
+3  A: 

You can set the php.ini value allow_url_fopen to true, then you can do this in a single line using file_get_contents() and file_put_contents():

file_put_contents($file, file_get_contents($url));
soulmerge
A: 

Maybe file_get_contents will work?

Oskar
A: 

Ok, well in case you need the output html source of a target page you could use CURL, by using library for its use with PHP.

If you need to open a php file and get this source, you'll probably have to edit the php configuration file to allow opening of php files by setting true the var allow_url_fopen.

Lopoc
A: 

I'd like to add to soulmerge answer the readfile function which do the same thing in only one call. http://us.php.net/manual/en/function.readfile.php

Arkh