trim().
Allows you to create a function which can be used to trim any matches from a mask. Trims the matching values from the start, end or both. These can either be used as part of a Higher Order Function such as array_map() or as part of a compiled/pipe function.
/**
* @param string $mask
* @return Closure(string):string
*/
Strings\trim(string $mask = "\t\n\r\0\x0B"): ClosureWhen Strings\trim() is called, it returns the following Closure which can be used like a regular function.
/**
* @param string $string The string to be trimmed
* @return string
* @psalm-pure
*/
$function(string $string): stringRelated Functions
This can be used to create a simple closure which can be used as a regular function.
// Create a closure which will get all instances of IT in a string.
$trimStar = Strings\trim('*');
// Called as a function.
echo $trimStar('*This is a string, with it in it*'); // This is a string, with it in it
// Used in a higher order function.
$array = array_map( $trimStar, ['**Hi*****', '***Bye']);
print_r($array); // ['Hi', 'Bye']This can be called inline using currying.
echo Strings\trim('_')('___This is a string, with it in it___'); // This is a string, with it in itIf you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.
$array = array_map(Strings\trim('-'), ['--Hi-', '-Bye']);
print_r($array); // ['Hi', 'Bye']