flatphp/sanitization

light sanitizer

v1.1.0 2020-05-10 03:35 UTC

This package is auto-updated.

Last update: 2024-12-10 13:31:40 UTC


README

light sanitizer

Install

composer require flatphp/sanitization

Usage

use \Flatphp\sanitization\sanitizer;

// sanitize one
$value = Sanitizer::sanitizeOne(' hello ', 'trim|upper');


// sanitize all
$data = [
    'v1' => '10.0',
    'v2' => ['a', 'b', 'c'],
    'v3' => ' hello '
];
$data = Sanitizer::sanitize($data, array(
    'v1' => 'int',
    'v2' => 'string:,|upper',
    'v3' => function($value){
        return strtoupper(trim($value));
    }
));


// just use single
$value = Sanitizer::toArray('1,2,3', ',');

Custom your own validate method 加入定制自己的验证方法

  • Use anonymous function like example
  • Just extends sanitizer class and add your own method (继承)
  • Or Just write global function (写全局函数)

Methods 已有的方法和规则