PHP code example of ali-eltaweel / codecs

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

    

ali-eltaweel / codecs example snippets


use Codecs\ICodec;

final class Base64Codec implements ICodec {

    public final function __construct(public readonly bool $strict = false) {}
    
    public final function encode(mixed $value): string {

        return base64_encode($value);
    }

    public final function decode(string $code): mixed {

        return base64_decode($code, $this->strict);
    }
}

$base64Codec = new Base64Codec();

var_dump(
    $base64Codec->encode('Hello, World!'),
    $base64Codec->decode($base64Codec->encode('Hello, World!'))
);