Interfaces
Syntax
Misc
String conversion
use Symfony\Component\String\ByteString;
use Symfony\Component\String\CodePointString;
use Symfony\Component\String\UnicodeString;
$content = new CodePointString('Hello world');
$content = new UnicodeString('नमस्ते दुनिया');
$content = new ByteString('さよなら');
$content = (new CodePointString('hello'))->toUnicodeString();
$content = UnicodeString::fromCodePoints(0x68, 0x65, 0x6C, 0x6C, 0x6F)->toByteString();
use function Symfony\Component\String\b;
use function Symfony\Component\String\u;
$content = b('hello');
$content = new ByteString('hello');
$content = u('hello');
$content = new UnicodeString('hello');
Object-oriented strings
if ('.html' === substr($theString, -strlen('.html'))) {
}
if (u($theString)->endsWith('.html')) {
}
$text =u('This is a déjà-vu situation.')
->trimEnd('.')
->replace('déjà-vu', 'jamais-vu')
->append('!');
u('FOO Bar')->folded();
u('Die O\'Brian Straße')->folded();
String Slugger
use Symfony\Component\String\Slugger\AsciiSlugger;
$slugger = new AsciiSlugger();
$slugger->slug('Стойността трябва', '-', 'bg');
$slugger->slug('Αυτή η τιμή πρέπει', '-', 'el');
$slugger->slug('该变量的值应为', '-', 'zh');
$slugger->slug('Wôrķšƥáçè sèťtïñğš');
Twig Integration
{{ 'Lorem ipsum'|u.truncate(8, '...') }}
{{ 'SymfonyStringWithTwig'|u.snake }}
Related