Download the PHP package carbonclean/sanitizer without Composer
On this page you can find all versions of the php package carbonclean/sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download carbonclean/sanitizer
More information about carbonclean/sanitizer
Files in carbonclean/sanitizer
Package sanitizer
Short Description Sanitization library for PHP and the Laravel framework.
License MIT
Informations about the package sanitizer
sanitizer
Sanitization library for PHP and the Laravel framework.
Installation
Usage
Will result in:
Laravel
In Laravel, you can use the Sanitizer through the Facade:
You may also Sanitize input in your own FormRequests by using the SanitizesInput trait, and adding a filters method that returns the filters that you want applied to the input.
Optional
If you are planning to use sanitizer for all of your HTTP requests, you can optionally disable
Laravel's TrimStrings
and ConvertEmptyStringsToNull
middleware from your HTTP kernel.
Then, instead, you can use trim
and empty_string_to_null
filters:
Available Filters
The following filters are available out of the box:
Filter | Description |
---|---|
trim | Trims a string |
empty_string_to_null | If the given string is empty set it to null |
escape | Escapes HTML and special chars using php's filter_var |
lowercase | Converts the given string to all lowercase |
uppercase | Converts the given string to all uppercase |
capitalize | Capitalize a string |
cast | Casts a variable into the given type. Options are: integer, float, string, boolean, object, array and Laravel Collection. |
format_date | Always takes two arguments, the date's given format and the target format, following DateTime notation. |
strip_tags | Strip HTML and PHP tags using php's strip_tags |
digit | Get only digit characters from the string |
boolean | If the given value is not a boolean set it to null |
Custom Filters
It is possible to use a closure or name of a class that implements CarbonClean\Sanitizer\Contracts\Filter
interface.
Laravel
You can easily extend the Sanitizer library by adding your own custom filters, just like you would the Validator library in Laravel, by calling extend from a ServiceProvider like so:
All versions of sanitizer with dependencies
illuminate/support Version ^6.0|^7.0|^8.0
illuminate/validation Version ^6.0|^7.0|^8.0
nesbot/carbon Version ^1.0|^2.0