PHP code example of petrknap / external-filter

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

    

petrknap / external-filter example snippets


use PetrKnap\ExternalFilter\Filter;

# echo "H4sIAAAAAAAAA0tJLEkEAGPz860EAAAA" | base64 --decode | gzip --decompress
echo Filter::new('base64', ['--decode'])
    ->pipe(Filter::new('gzip', ['--decompress']))
    ->filter('H4sIAAAAAAAAA0tJLEkEAGPz860EAAAA');

use PetrKnap\ExternalFilter\Filter;

$errorStream = fopen('php://memory', 'w+');

Filter::new('php')->filter(
    ' fputs(fopen("php://stderr", "w"), "error");',
    error: $errorStream,
);

rewind($errorStream);
echo stream_get_contents($errorStream);
fclose($errorStream);

use PetrKnap\ExternalFilter\Filter;

echo Filter::new(phpSnippet: 'fputs(STDOUT, fgets(STDIN));')
    ->filter(b'data');