Sanitize::removeTags() ->lowercase() ->sanitize('<b>Hello World!</b>'); // output: hello world!
(new Sanitize)->removeTags()->lowercase()->sanitize('<b>Hello World!</b>');
$s = Sanitize::call('mb_strtolower', ['UTF-8']); $s->sanitize(' !'); // output: !
$s = Sanitize::unserialize()->removeTags()->trim() $s->sanitize('{"name" : " <b> Tom </b> "}'); /* output: [ 'name' => 'Tom' ] */
$input = [ 'name' => '<b>Tom</b>', 'age' => -22 ]; $attributes = [ 'name' => Sanitize::removeTags(), 'age' => Sanitize::abs() ]; Sanitize::attributes($attributes)->sanitize($input); /* output: [ 'name' => 'Tom', 'age' => 22 ] */
$input = [ 'name' => '<b>Tom</b>', 'email' => '<b>tom@site.com</b>', ]; Sanitize::attributes(Sanitize::removeTags())->sanitize($input); /* output: [ 'name' => 'Tom', 'email' => 'tom@site.com' ] */
$input = [ 'name' => '<b>Tom</b>', 'other' => [ 'email' => '<b>tom@site.com</b>', 'note' => [ '<b>text...</b>' ] ] ]; Sanitize::attributes(Sanitize::removeTags())->sanitize($input); /* output: [ 'name' => 'Tom', 'other' => [ 'email' => 'tom@site.com', 'note' => [ 'text...' ] ] ] */
Sanitize::recursive(false)->attributes(Sanitize::removeTags());
$input = [ 'name' => '<b> Tom</b>', 'email' => '<b>tom@site.com </b>', 'age' => -22, ]; $s = Sanitize::attributes([ 'age' => Sanitize::abs(), '*' => Sanitize::removeTags()->trim() ]); $s->sanitize($input); /* output: [ 'name' => 'Tom', 'email' => 'tom@site.com', 'age' => 22, ] */
Sanitize::labelRemainder('_remainder');
A similar feature is now available in Rock Validate.
$input = [ 'name' => '<b>Tom</b>', 'other' => [ 'tel' => '<b>777-777</b>', 'email' => '<b>tom@site.com</b>', 'note' => [ 'first' => '<b> text... </b> ', ] ] ]; $attributes = [ 'other.email' => Sanitize::removeTags(), 'other.note.first' => Sanitize::removeTags()->trim() ]; Sanitize::attributes($attributes)->sanitize($input); /* output: [ 'name' => '<b>Tom</b>', 'other' => [ 'tel' => '<b>777-777</b>', 'email' => 'tom@site.com', 'note' =>[ 'first' => 'text...', ] ] ] */
use rock\sanitize\rules\Rule class Round extends Rule { protected $precision = 0; public function __construct($precision = 0) { $this->precision= $precision; } public function sanitize($input) { return round($input, $this->precision); } }
$config = [ 'rules' => [ 'round' => \namespace\to\Round::className() ] ]; $s = new Sanitize($config); $s->round()->sanitize(7.4); // output: 7.0
composer require romeoz/rock-sanitize:*
Source: https://habr.com/ru/post/254045/
All Articles