Strings

Curried wrappers around PHP’s native string functions — every one of them is a value-first callable that binds the “how” up front so the subject string can be fed in later. Drop them into array_map, compose them into pipelines, or use them as predicates for filters.

Manipulation

$shoutWrap = F\compose(
    Str\trim(),
    'strtoupper',
    Str\wrap('[ ', ' ]')
);

$shoutWrap('  hello  ');   // '[ HELLO ]'

Also: append, prepend, replaceWith, replaceSubString, findToReplace, translateWith, pad, repeat, slice, stripTags.

Predicates

$containsFoo = Str\contains('foo');
$containsFoo('its foo');   // true
$containsFoo('its bar');   // false

Str\isBlank('');    // true
Str\isBlank('   '); // false  — whitespace is not blank
Str\isBlank(null);  // false  — only a zero-length string counts

Also: startsWith, endsWith, containsPattern.

Splits and positions

$splitCsv = Str\split(',');
$splitCsv('a,b,c');        // ['a', 'b', 'c']

$firstPos = Str\firstPosition('e');
$firstPos('hello');        // 1
$firstPos('world');        // NULL  — not found

Also: splitByLength, splitPattern, lastPosition, firstSubString, firstChar, lastChar, countChars, countSubString.

Composition helpers

composeSafeStringFunc — compose several string-returning callables with an is_string guard between every step. stringCompiler — an accumulator for building strings across successive calls.

Formatting & trimming

trim, lTrim, rTrim, wordWrap, wordCount, digit (number formatting → string), vSprintf, chunk, addSlashes, similar.

Deep-dive examples

String Functions