PHP code example of dtimofeev / sanitizer
1. Go to this page and download the library: Download dtimofeev/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/ */
dtimofeev / sanitizer example snippets
use Sanitizer\Sanitizer;
use Sanitizer\SanitizerSchema as SS;
// Single element
$processed = Sanitezer::process(true, SS::boolean());
// Complex schema
$processed = Sanitizer::process($input, SS::arr()->schema([
'id' => SS::integer()->min(1),
'nickname' => SS::string()->alphaNum(),
'email' => SS::string()->email(),
'ip' => SS::string()->ip(),
'sex' => SS::string()->optional('na')->oneOf(['male', 'female', 'na']),
'favMovies' => SS::arr()->each(
SS::arr()->schema([
'title' => SS::string()->trim()->max(200),
'release' => SS::date()->format('Y-m-d H:i:s'),
'tags' => SS::arr()->unique()->each(
SS::string()->alphaNum()
),
])
),
]));
SS::createAlias('alphaNum', SS::string()->alphaNum());
$processed = Sanitizer::process($input, SS::arr()->schema([
'nickname' => SS::alias('alphaNum'),
'favMovies' => SS::arr()->each(
SS::arr()->schema([
'tags' => SS::arr()->unique()->each(SS::alias('alphaNum')),
])
),
]));