in dev, please do not use in production
$s = new Str('Hello, 世界');
$s->last(2); // 世界
$s->chars(); // ['H','e','l','l','o',',',' ','世','界']
$s
->ensureLeft('H') // Hello, 世界
->ensureRight('!!!') // Hello, 世界!!!
->trimRight('!') // Hello, 世界
->append('Str say - '); // Str say - Hello, 世界
$send = function (string $s) {};
$send((string)$s); // same
$send($s->toString()); // same
$send($s->getString()); // same
A fast string manipulation library with multibyte support. Based on "Stringy" library, with focus on speed.
Lib uses php7 features and does not throw any exceptions (because all input parameters are strongly typed). The code is completely covered by unit tests)
Requirements:
- php7.0
composer require str/str
- ensureLeft
- ensureRight
- hasPrefix
- hasSuffix
- contains
- replace - add limit param
- toLowerCase
- toUpperCase
- trim
- trimLeft
- trimRight
- append
- prepend
- at
- substr
- chars
- first
- last
- length
- indexOf
- indexOfLast
- countSubstr
- containsAll
- containsAny
- startsWith
- startsWithAny
- endsWith
- endsWithAny
- pad
- padBoth
- padLeft
- padRight
- insert
- removeLeft
- removeRight
- repeat
- reverse
- shuffle
- between
- camelize
- collapseWhitespace
- dasherize
- delimit
- lowerCaseFirst
- regexReplace
- upperCaseFirst
- isUUIDv4
- hasLowerCase
- hasUpperCase
- htmlDecode
- htmlEncode
- humanize
- isAlpha
- isAlphanumeric
- isBase64
- isBlank
- isHexadecimal
- isJson
- isLowerCase
- isSerialized
- isUpperCase
- lines
- longestCommonPrefix
- longestCommonSuffix
- longestCommonSubstring
- safeTruncate
- slugify
- slice
- split
- stripWhitespace
- surround
- swapCase
- tidy
- titleize
- toAscii
- toBoolean
- toSpaces
- toTabs
- toTitleCase
- truncate
- underscored
- upperCamelize
./vendor/bin/phpbench run --report=str
./vendor/bin/phpbench run -o markdown --report=str
Test subjects:
- FS (str/str)
- Stringy (danielstjules/Stringy)
subject | mode | mem_peak | diff |
---|---|---|---|
bench_StrStatic | 239.000μs | 1,328,496b | 1.00x |
bench_Str | 482.000μs | 1,355,320b | 2.02x |
bench_Stringy | 1,479.000μs | 1,872,552b | 6.19x |
bench_StringyStatic | 1,790.000μs | 1,894,024b | 7.49x |