PHP code example of inpsyde / filter

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

    

inpsyde / filter example snippets


$filter = new Inpsyde\Filter\DateTime();
$value = $filter->filter( '21.06.1987' ); // converts to: 1987-06-21

$options = [
    'format' => 'd.m.Y'
];
$filter = new Inpsyde\Filter\DateTime( $options );
$value = $filter->filter( '1987-06-21' ); // 21.06.1987

namespace My\Own\Filter;

use Inpsyde\Filter\AbstractFilter;

class YourFilter extends AbstractFilter {

    /**
     * Optional: set some options, which can be overwritten by constructor.
      
     * @var array
     */
    protected $options = [
        'key' => 'value'
    ];

    /**
     * {@inheritdoc}
     */
    public function filter( $value ) {
       // do something
       return $value;
    }

}

// Optional: set "new value" to Filter.
$options = [ 'key' => 'new value' ];

$filter = new YourFilter( $options );
$value = $filter->filter( 'my value' );

$factory = new \Inpsyde\Filter\FilterFactory();
$filter = $factory->create( 'DateTime' ); // returns instance of \Inpsyde\Filter\DateTime

$factory = new \Inpsyde\Filter\FilterFactory();
$filter = $factory->create( My\Own\Filter\YourFilter::class ); // Creates an instance of your own filter.