PHP code example of minter / php-rlp

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

    

minter / php-rlp example snippets


use Web3p\RLP\RLP;

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

// to string, encoding: ascii utf8 hex
$encodedBuffer->toString($encoding);

use Web3p\RLP\RLP;

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

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

// show dog
echo $decodedArray[0]->toString('utf8');

use Web3p\RLP\RLP;

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


use Web3p\RLP\RLP;

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

// echo web3p
echo $decodedArray[0]->toString('utf8');

// echo ethereum
echo $decodedArray[1]->toString('utf8');

// echo solidity
echo $decodedArray[2]->toString('utf8');