https://github.com/siriusphp/filtration
Array filtering/sanitization
https://github.com/siriusphp/filtration
Last synced: 11 days ago
JSON representation
Array filtering/sanitization
- Host: GitHub
- URL: https://github.com/siriusphp/filtration
- Owner: siriusphp
- License: mit
- Created: 2013-08-25T09:01:57.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T07:09:00.000Z (about 6 years ago)
- Last Synced: 2025-09-18T14:36:40.088Z (6 months ago)
- Language: PHP
- Size: 108 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#Sirius\Filtration
[](https://github.com/siriusphp/filtration)
[](https://github.com/siriusphp/filtration/releases)
[](https://github.com/siriusphp/filtration/blob/master/LICENSE)
[](https://travis-ci.org/siriusphp/filtration)
[](https://scrutinizer-ci.com/g/siriusphp/filtration/code-structure)
[](https://scrutinizer-ci.com/g/siriusphp/filtration)
PHP library for array filtering/sanitization
Sometimes you want to make sure the values pushed by a source (eg: a user when submits a form) follow some restrictions like
- no space at the beginning or the end for the title of a page
- no HTML code in a comment sent by a user
- no spaces in the field which represents the URL
- remove XSS attacks
- etc...
Other times you want to make sure that the data you send to the user is parsed before displaying. For example you may want to:
- convert markdown into HTML
- convert URLs into links
- apply a localized format to dates
- etc ()
To achieve this end result you need to filter the values. This is where SiriusFiltration comes into place
## Elevator pitch
```php
use Sirius\Filtration\Filtrator;
$filtrator = new Filtrator();
// add filters for title
$filtrator->add('title', 'trim');
$filtrator->add('title', 'strip_tags');
$filtrator->add('title', 'nullify');
// add filters for content in one go
$filtrator->add('content', [
'trim'
]);
$result = $filtrator->filter(array(
'title' => '
My title has tags and is awesome
',
'content' => ' My content was trimmed'
));
/* $result is
array(
'title' => NULL ,
'content' => 'My content was trimmed'
)
*/
```
## Links
- [documentation](http://www.sirius.ro/php/sirius/validation/)
- [changelog](CHANGELOG.md)