urmaul / formatter
Rule-based string format.
v1.5.0
2015-10-23 13:05 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-09 16:06:42 UTC
README
Rule-based string formatters. Made for polishing parsed data.
Installing
composer require urmaul/formatter dev-master
Using
$values = ['foo' => ' bar ', 'spam' => 'ham | foo | bar']; $formatter = new Formatter([ ['foo', 'trim'], ['spam', 'cut', ' | '], ]); $values = $formatter->format($values); // $values = ['foo' => 'bar', 'spam' => 'ham'];
Actions
- cut(delimiter) - returns string part between beginning and delimiter.
- rcut(delimiter) - returns string part between delimiter and ending.
- remove(substring) - removes substring. See str_replace.
- replace(substring, replacement) - replaces substring with replacement. See str_replace.
- removeMatch(pattern) - removes pattern. See preg_replace.
- replaceMatch(pattern, replacement) - replaces pattern with replacement. See preg_replace.
- map(array map) - replaces string with value from map.
- between(leftBorder, rightBorder) - returns string part between first occurence of leftBorder and rightBorder.
- trim([character_mask = " \t\n\r\0\x0B"]) - strips whitespace (or other characters) from the beginning and end of a string.
- callback(callable) - processes string with callback.
- grep(substring) - returns lines containing substring.
- stripTags([allowable_tags]) - strips HTML and PHP tags from a string. See strip_tags.
- iconv([encoding_from, encoding_to]) - converts character encoding. Defaults are "UTF-8" - "UTF-8//IGNORE" which remove invalid characters from utf-8 string.
- stripWhitespaces(string) - returns string without unprintable characters.