1. Go to this page and download the library: Download chr15k/string 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/ */
$string = s('/foo/bar/baz')->basename();
// 'baz'
// If needed, you may provide an "extension" that will be removed from the trailing component:
$string = s('/foo/bar/baz.jpg')->basename('.jpg');
// 'baz'
$slice = s('This is my name')->before('my name');
// 'This is '
$slice = s('This is my name')->beforeLast('is');
// 'This '
$converted = s('foo_bar')->camel();
// fooBar
$contains = s('This is my name')->contains('my');
// true
// You can also pass an array:
$contains = s('This is my name')->contains(['my', 'foo']);
// true
$containsAll = s('This is my name')->containsAll(['my', 'name']);
// true
$string = s('/foo/bar/baz')->dirname();
// '/foo/bar'
// Optionally pass directory levels as second argument:
$string = s('/foo/bar/baz')->dirname(2);
// '/foo'
$result = s('This is my name')->endsWith('name');
// true
// You can also pass an array
$result = s('This is my name')->endsWith(['name', 'foo']);
// true
$result = s('This is my name')->endsWith(['this', 'foo']);
// false
$truncated = s('The quick brown fox jumps over the lazy dog')->limit(20);
// The quick brown fox...
// pass second argument to append something other than '...'
$truncated = s('The quick brown fox jumps over the lazy dog')->limit(20, ' (...)');
// The quick brown fox (...)
$plural = s('car')->plural();
// cars
$plural = s('child')->plural();
// children
// Pass second argument as a count to determine singular or plural form of a string:
$plural = s('child')->plural(2);
// children
$plural = s('child')->plural(1);
// child
$string = s('World')->prepend('Hello ');
// Hello World
$replaced = s('Hello World')->replace('World', 'Chris');
// Hello Chris
$string = 'The event will take place between ? and ?';
$replaced = s($string)->replaceArray('?', ['8:30', '9:00']);
// The event will take place between 8:30 and 9:00
$replaced = s('the quick brown fox jumps over the lazy dog')->replaceFirst('the', 'a');
// a quick brown fox jumps over the lazy dog
$replaced = s('the quick brown fox jumps over the lazy dog')->replaceLast('the', 'a');
// the quick brown fox jumps over a lazy dog
$plural = Str::plural('bus');
// buses
$plural = Str::plural('child');
// children
// Pass second argument to retrieve the singular or plural form of the string...
$plural = Str::plural('child', 2);
// children
$plural = Str::plural('child', 1);
// child
$string = 'The event will take place between ? and ?';
$replaced = Str::replaceArray('?', ['8:30', '9:00'], $string);
// The event will take place between 8:30 and 9:00
$replaced = Str::replaceFirst('the', 'a', 'the quick brown fox jumps over the lazy dog');
// a quick brown fox jumps over the lazy dog
$replaced = Str::replaceLast('the', 'a', 'the quick brown fox jumps over the lazy dog');
// the quick brown fox jumps over a lazy dog
$singular = Str::singular('cars');
// car
$singular = Str::singular('children');
// child
$slug = Str::slug('Chris The Coder', '-');
// chris-the-coder