1. Go to this page and download the library: Download mvanvu/php-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/ */
mvanvu / php-filter example snippets
use MaiVu\Php\Filter;
class CustomFilter extends Filter
{
public static function arrayInteger($value)
{
return static::clean($value, 'int:array');
}
}
// Return '[1, 2, 3]'
echo '<pre>' . print_r(CustomFilter::clean(['1abc2', '2b', 3], 'arrayInteger'), true) . '</pre>';
php
use MaiVu\Php\Filter;
Filter::setRule('custom', function($value) {
return $value . ' is filtered by a Closure';
});
$source = 'Hello World!';
// Return 'Hello World! is filtered by a Closure'
$filtered = Filter::clean($source, 'custom');
// The same above
Filter::clean($source, function($value) {
return $value . ' is filtered by a Closure';
});