PHP code example of voku / stringy
1. Go to this page and download the library: Download voku/stringy library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
voku / stringy example snippets
// Standard library
strtoupper('fòôbàř'); // 'FòôBàř'
strlen('fòôbàř'); // 10
// mbstring
mb_strtoupper('fòôbàř'); // 'FÒÔBÀŘ'
mb_strlen('fòôbàř'); // '6'
// Stringy
$stringy = Stringy\Stringy::create('fòôbàř');
$stringy->toUpperCase(); // 'FÒÔBÀŘ'
$stringy->length(); // '6'
// Portable UTF-8
use voku\helper\UTF8;
UTF8::strtoupper('fòôbàř'); // 'FÒÔBÀŘ'
UTF8::strlen('fòôbàř'); // '6'
use Stringy\Stringy as S;
use Stringy\Stringy as S;
echo S::create('fòô bàř')->collapseWhitespace()->swapCase(); // 'FÒÔ BÀŘ'
$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'
$stringyCollection = \Stringy\collection(['fòôbàř', 'lall', 'öäü']);
php
$stringy = S::create('fòôbàř');
foreach ($stringy as $char) {
echo $char;
}
// 'fòôbàř'
php
$stringy = S::create('fòô');
count($stringy); // 3
php
$stringy = S::create('bàř');
echo $stringy[2]; // 'ř'
echo $stringy[-2]; // 'à'
isset($stringy[-4]); // false
$stringy[3]; // OutOfBoundsException
$stringy[2] = 'a'; // Exception
php
use function Stringy\create as s;
// Instead of: S::create('fòô bàř')
s('fòô bàř')->collapseWhitespace()->swapCase();
$this->str