PHP code example of taproot / archive

1. Go to this page and download the library: Download taproot/archive library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

taproot / archive example snippets




$archive = new Taproot\Archive(__DIR__ . '/data/');



list($response, $err) = $archive->archive('http://indiewebcamp.com/Taproot');
if ($err !== null) {
	// handle the exception, which is an instance implementing Guzzle\Common\Exception\GuzzleException
} else {
	echo $response->getBody(true);
}

// The data directory now looks something like this:
// 	data/
// 		http/
// 			indiewebcamp.com/
// 				Taproot/
// 					YYYY-MM-DDTHHMMSS.html
// 					YYYY-MM-DDTHHMMSS-headers.txt




$url = 'http://waterpigs.co.uk/notes/1000';

list($resp, $err) = $archive->get($url);
if ($err !== null) {
	// Failure! There was no archived copy of that URL, and fetching it from the server returned an error response
} else {
	// Success! Either there was an archived copy, in which case the latest one was returned, or the URL was archived as if $archive->archive($url) had been called.
}

$versions = $archive->archives($url);
// $versions is an array of string archive IDs which match the form 'YYYY-MM-DDTHHMMSS'

// getResponse allows you to get a particular archived version of a URL
list($resp, $err) = $archive->getResponse($url, $versions[0]);