PHP code example of okipa / php-data-sanitizer

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

    

okipa / php-data-sanitizer example snippets


// php data sanitizer
// https://github.com/Okipa/php-data-sanitizer
$this->app->register(Okipa\DataSanitizer\Laravel\DataSanitizerServiceProvider::class);

'aliases' => [
    '...',
    'DataSanitizer' => Okipa\DataSanitizer\Laravel\Facades\DataSanitizer::class
]

public function index()
{
    $data = [
        // data to sanitize
    ];
    $sanitizedData = \DataSanitizer::sanitize($data);
}

// import the package facade
use Acid\DataSanitizer\Native\Facades\DataSanitizer;

// sanitize your data
$data = ['false', '3', ''];
$sanitizedData = DataSanitizer::sanitize($data);

// produces [false, 3, null]

$data = ['null', 'true'];
$sanitizedData = DataSanitizer::sanitize($data);

''                  => null
' string trim '     => 'string trim'
'null'              => null
'false'             => false
'true'              => true
'on'                => true
'3'                 => 3
'5.07'              => 5.07

DataSanitizer::sanitize('', 'hello');
// will return 'hello'

$jsonDecodeAssoc = true // default is false
$data = json_decode($data, null, $jsonDecodeAssoc);
// will decode your json as associative array (and as object if false)