https://github.com/truongwp/sanitizer
A simple and stand-alone PHP sanitizer library with no dependencies.
https://github.com/truongwp/sanitizer
php php-library sanitization sanitizer
Last synced: 6 months ago
JSON representation
A simple and stand-alone PHP sanitizer library with no dependencies.
- Host: GitHub
- URL: https://github.com/truongwp/sanitizer
- Owner: truongwp
- Created: 2017-05-30T08:24:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-01T16:11:48.000Z (over 8 years ago)
- Last Synced: 2025-02-25T00:38:39.538Z (8 months ago)
- Topics: php, php-library, sanitization, sanitizer
- Language: PHP
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Sanitizer
**Sanitizer** is a simple and stand-alone PHP sanitizer library with no dependencies.
### Installation
Uses Composer to install and update:
```
composer require "truongwp/sanitizer=*"
```**Sanitizer** require PHP >= 5.3
### Usage
```php
' Foo bar ',
'age' => ' 24 ',
);$rules = array(
'name' => 'trim|strtolower|ucwords',
'age' => 'intval',
);$output = $sanitizer->sanitize($input, $rules);
```The `$output`:
```php
array(
'name' => 'Foo Bar',
'age' => 24,
);
```Multiple rules can be passed as string delimiter by `|` or use an array:
```php
array('trim', 'strtolower', 'ucwords'),
'age' => 'intval',
);
```By default, rule name is PHP function. So you can easily add a custom function to sanitize.
```php
'//foo',
);
$rules = array(
'name' => 'trim_slasses',
);
$output = $sanitizer->sanitize($input, $rules);
```The result:
```php
array(
'name' => 'foo',
)
```If you want to pass additional parameters to sanitizer function, you can append them to rule name and delimited by `:`.
```php
'foo',
);
$rules = array(
'name' => 'prefix_suffix:prefix_:_suffix',
);
$output = $sanitizer->sanitize($input, $rules);
```The result:
```php
array(
'name' => 'prefix_foo_suffix',
)
```You can also add custom sanitizer class by using SanitizerRegistry.
```php
'05/30/2017',
);
$rules = array(
'name' => 'date_format:Y-m-d',
);
$output = $sanitizer->sanitize($input, $rules);
```The result:
```php
array(
'day' => '2017-05-30',
)
```### Contributing
Contributor: [@truongwp](https://truongwp.com)Bug reports or Pull requests are welcome.