PHP code example of danny50610 / php-cid
1. Go to this page and download the library: Download danny50610/php-cid 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/ */
danny50610 / php-cid example snippets
use Danny50610\Cid\CID;
use Danny50610\Cid\Codec;
use Danny50610\Cid\Multihash;
use Danny50610\Cid\MultihashType;
// true for binary
$hash = hash('sha256', 'The quick brown fox jumped over the lazy dog.', true);
$type = MultihashType::get('sha2_256');
// v0
$multihash = new Multihash($type, $hash);
$cidv0 = CID::makeV0($multihash);
print($cidv0 . PHP_EOL); // QmVPKnh2nScP7zfMWFEC6JAcruqxPncbMmAMa98AiMZCZQ
// v1
$cidv1 = new CID(1, Codec::get('DagProtobuf'), $type, $hash);
print($cidv1 . PHP_EOL); // zdj7WcUaA86dv5yzhyHEzBoxg1BV83Q7L2jE5ZtEwWqXo86jL