PHP code example of jijoel / sanitization-filters

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

    

jijoel / sanitization-filters example snippets


$data = [
    'first_name'    =>  'john',
    'last_name'     =>  '<strong>DOE</strong>',
    'email'         =>  '  [email protected]',
    'birthdate'     =>  '06/25/1980',
    'jsonVar'       =>  '{"name":"value"}',
];

use \Waavi\Sanitizer\Sanitizer;

$filters = [
    'first_name'    =>  'trim|escape|capitalize',
    'last_name'     =>  'trim|escape|capitalize',
    'email'         =>  'trim|escape|lowercase',
    'birthdate'     =>  'trim|format_date:m/d/Y, Y-m-d',
    'jsonVar'       =>  'cast:array',
];

$sanitizer  = new Sanitizer($data, $filters);
var_dump($sanitizer->sanitize());

[
    'first_name'    =>  'John',
    'last_name'     =>  'Doe',
    'email'         =>  '[email protected]',
    'birthdate'     =>  '1980-06-25',
    'jsonVar'       =>  '["name" => "value"]',
];

'providers' => [
    ...
    Waavi\Sanitizer\Laravel\SanitizerServiceProvider::class,
    Jijoel\Sanitizer\Laravel\SanitizerServiceProvider::class,
];

use Waavi\Sanitizer\Laravel\SanitizesInput;

class MyFormRequest extends FormRequest
{
    use SanitizesInput;

    public function filters()
    {
        return [
            'name' => 'trim|escape|name',
            'email' => 'trim|escape|lower',
        ];
    }

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