A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM.
s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
Refer to the 1.x branch or 2.x branch for older documentation.
Why?
In part due to a lack of multibyte support (including UTF-8) across many of
PHP's standard string functions. But also to offer an OO wrapper around the
mbstring
module's multibyte-compatible functions. Stringy handles some quirks,
provides additional functionality, and hopefully makes strings a little easier
to work with!
// Standard library
strtoupper('fòôbàř'); // 'FòôBàř'
strlen('fòôbàř'); // 10
// mbstring
mb_strtoupper('fòôbàř'); // 'FÒÔBÀŘ'
mb_strlen('fòôbàř'); // '6'
// Stringy
s('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'
s('fòôbàř')->length(); // '6'
Installation
If you're using Composer to manage dependencies, you can include the following in your composer.json file:
"require": {
"danielstjules/stringy": "~3.1.0"
}
Then, after running composer update
or php composer.phar update
, you can
load the class using Composer's autoloading:
require 'vendor/autoload.php';
Otherwise, you can