zenstruck / string
String utilities
Fund package maintenance!
kbond
Installs: 32 204
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- twig/twig: ^2.10
README
Various string utility functions for PHP. A Twig Extension is available.
Installation
composer require zenstruck/string
Usage
remove_whitespace
Replaces
with a single space and converts multiple sequential spaces into a
single space.
$ret = remove_whitespace(" foo \n\n\n \r bar"); // $ret = "foo bar"
null_trim
Similar to core "trim" but returns null instead of an empty string. When an array is passed, all elements get processed recursively.
$ret = null_trim(" foo bar "); // $ret = "foo bar" $ret = null_trim(" "); // $ret = null $ret = null_trim(array(" foo bar ", " ")); // $ret = array("foo bar", null) $ret = null_trim("foo / ", "/ "); // $ret = "foo"
truncate_word
Truncates text to a length without breaking words (calls remove_whitespace
before truncating).
$ret = truncate_word(" foo bar baz", 10); // $ret = "foo bar..."