Object-oriented string manipulation library
- PHP >= 8.1
Use composer to add the package to your dependencies:
composer require palmtree/string
use function Palmtree\String\s;
$str = s('foo bar baz');
$str->startsWith('foo'); // true
$str->endsWith('baz'); // true
$str->contains('bar'); // true
$str->replace('bar', 'qux'); // 'foo qux baz'
$str->after('bar'); // ' baz'
$str->afterLast('b'); // 'az'
$str->beforeFirst('b'); // 'foo '
$str->kebab(); // 'foo-bar-baz'
$str->camel(); // 'fooBarBaz'
$str->snake(); // 'foo_bar_baz'
Many other methods are provided. Read through the documented source code to see more.
Released under the MIT license