PHP code example of phpfluent / filter

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

    

phpfluent / filter example snippets


use PHPFluent\Filter\Builder as f;

f::stringToUpper()->filter('phpfluent'); // returns: 'PHPFLUENT'

f::stringToUpper()
 ->stringTrim()
 ->filter('filter    '); // returns 'FILTER'

f::json_encode(JSON_PRETTY_PRINT)
 ->filter(array('key' => 'value')); // returns: '{"key": "value"}'

$builder = new PHPFluent\Filter\Builder();
$builder->ucfirst();
$builder->str_pad(10, '-');
$builder->filter('filter'); // returns: 'Filter----'

$builder('filter'); // returns: 'Filter----'

f::myFilter();

f::getDefaultFactory()->appendPrefix('My\\Filter\\Prefix');

use PHPFluent\Filter\FilterInterface;

class UrlFilter implements FilterInterface
{
    public function filter($value)
    {
        return filter_var($value, FILTER_SANITIZE_URL);
    }
}

$factory = new PHPFluent\Filter\Factory();
$factory->prependPrefix('My\\Zend\\Filters\\');

PHPFluent\Filter\Builder::setDefaultFactory($factory);

$factory = new PHPFluent\Filter\Factory();
$factory->prependPrefix('My\\Zend\\Filters\\');

$builder = new PHPFluent\Filter\Builder($factory);

f::key('foo', f::boolean())
    ->filter(array('foo' => 1, 'baz' => 'Whatever')); // array('foo' => true)