PHP code example of mrinte / rlp

1. Go to this page and download the library: Download mrinte/rlp 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/ */

    

mrinte / rlp example snippets


use Web3p\RLP\RLP;

$rlp = new RLP;
// c483646f67
$encoded = $rlp->encode(['dog']);

// 83646f67
$encoded = $rlp->encode('dog');

use Web3p\RLP\RLP;
use Web3p\RLP\Types\Str;

$rlp = new RLP;
$encoded = $rlp->encode(['dog']);

// only accept 0x prefixed hex string
$decoded = $rlp->decode('0x' . $encoded);

// show 646f67
echo $decoded[0];

// show dog
echo hex2bin($decoded[0]);

// or you can
echo Str::decodeHex($decoded[0]);

use Web3p\RLP\RLP;

$rlp = new RLP;
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);

use Web3p\RLP\RLP;
use Web3p\RLP\Types\Str;

$rlp = new RLP;
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);
$decoded = $rlp->decode('0x' . $encoded);

// echo web3p
echo hex2bin($decoded[0]);

// echo ethereum
echo hex2bin($decoded[1]);

// echo solidity
echo hex2bin($decoded[2]);

// or you can
echo Str::decodeHex($decoded[0]);
echo Str::decodeHex($decoded[1]);
echo Str::decodeHex($decoded[2]);