How to copy everything from a site and save it to a txt file

1

Well, what I'm going to do is relatively simple:

I want to copy the whole code from this link:

link

And save to a txt file.

How can I do this with PHP?

Thank you.

    
asked by anonymous 25.03.2017 / 16:21

1 answer

2

You can do with curl like this:

<?php
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://steamcommunity.com/profiles/76561198337627631/inventory/json/730/2/');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'MOZILLA YOOO');
$page = curl_exec($curl_handle);
curl_close($curl_handle);
$f_handler = fopen('test.txt', 'w');
fwrite($f_handler, $page);

And with file_get_contents:

<?php
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "User-Agent: Mozzila yooo\r\n"
  )
);
$context = stream_context_create($opts);
$page = file_get_contents('http://steamcommunity.com/profiles/76561198337627631/inventory/json/730/2/', false, $context);
$f_handler = fopen('test.txt', 'w');
fwrite($f_handler, $page);
    
25.03.2017 / 16:41