PHP code example of fadion / sanitizer

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

    

fadion / sanitizer example snippets


use Fadion\Sanitizer\Sanitizer;

$inputs = ['name' => 'John', 'age' => 31];
$sanitizers = ['name' => 'trim', 'age' => 'int'];

$sanitizer = new Sanitizer;
$newInputs = $sanitizer->run($inputs, $sanitizers);

$sanitizersOne = [
    'name' => ['trim', 'ucfirst'],
    'age' => 'int'
];

$sanitizersSecond = [
    'name' => 'trim|ucfirst',
    'age' => 'int'
];

$sanitizers = [
    'name' => ['trim', function($value) {
        return str_replace('John', 'Will', $value);
    }],
    'age' => function($value) {
        return $value + 100;
    }
];

$sanitizers = [
    'expire' => 'date:m/d/Y',
    'number' => 'number_format:3',
    'body' => 'limit:100',
    'credit_card' => 'mask:+'
];

$inputs = [/* some inputs */];
$sanitizers = [/* some sanitizers */];

$newInputs = Sanitizer::run($inputs, $sanitizers);

namespace App\Http\Requests;

use Fadion\Sanitizer\FormRequest\Sanitizable;

class UserRequest extends Request
{
    use Sanitizable;

    public function rules()
    {
        return [
            'name' => '

\Fadion\Sanitizer\Sanitizer::register('upper_some', function($value) {
    $some = mt_rand(1, strlen($value) - 1);
    return strtoupper(substr($value, 0, $some)).substr($value, $some);
});

// some service provider
public function boot()
{
    \Fadion\Sanitizer\Sanitizer::register('upper_some', function($value) {
        $some = mt_rand(1, strlen($value) - 1);
        return strtoupper(substr($value, 0, $some)).substr($value, $some);
    });
}

$sanitizers = [
    'name' => 'trim|upper_some'
];