extphp / formatter
A great way to quickly format a given set of variables
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/extphp/formatter
Requires (Dev)
- phpunit/phpunit: ^5.0 || ^6.0 || ^7.0
This package is auto-updated.
Last update: 2025-09-29 02:09:02 UTC
README
A great way to quickly format a given set of variables.
This project was highly inspired by the Laravel Validator.
Usage
<?php use ExtPHP\Formatter\Formatter; $data = [ 'id' => '153', 'first_name' => 'mary j.', 'last_name' => 'blige', 'female' => 1, 'married' => 'false', 'cash' => '2761,32' ]; $rules = [ 'id' => 'cast:int', 'first_name' => 'ucwords', 'last_name' => 'strtoupper', 'female' => 'cast:ebool', 'married' => 'cast:ebool', 'cash' => 'str_replace:\,,.|cast:float|number_format:4,\,,.' ]; $formatter = new Formatter($data, $rules); $formatted = $formatter->format(); var_dump($formatted);
// the above code will output
array(6) {
["id"]=>
int(153)
["first_name"]=>
string(7) "Mary J."
["last_name"]=>
string(5) "BLIGE"
["female"]=>
bool(true)
["married"]=>
bool(false)
["cash"]=>
string(10) "2.761,3200"
}