Quick start
Quick overview of the library
Creating a new multibyte string is done by using the static method from
.
use Opis\String\UnicodeString as wstring;
$str = wstring::from('ăĂâÂîÎşŞţŢ');
By default, it’s assumed that your string is encoded using UTF-8.
If your string is encoded using another encoding,
you can pass the name of the encoding as the second argument of the from
method.
use Opis\String\UnicodeString as wstring;
$str = wstring::from($string, 'ISO-8859-1');
Once created, you can use the resulted object in the same manner in which you would use a regular string.
echo $str; //> ăĂâÂîÎşŞţŢ
echo 'foo ' . $str . ' bar'; //> foo ăĂâÂîÎşŞţŢ bar
echo $str[0]; //> ă
echo $str[4]; //> î
You can chain multiple methods to perform operations against a string.
use Opis\String\UnicodeString as wstring;
$str = wstring::from('ăĂâÂîÎşŞţŢ');
echo $str->substring(3, 4)
->toUpper(); //> ÂÎÎŞ
The UnicodeString
instances are immutable and work
in a similar manner as C# or Java strings.
use Opis\String\UnicodeString as wstring;
$str = wstring::from('abcd');
echo $str->toUpper(); //> ABCD
echo $str; //> abcd