1. Go to this page and download the library: Download laraplus/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/ */
laraplus / string example snippets
str(' some text ')->trim()->substring(0, 4);
// instead of
substr(trim(' some text '), 0, 4);
str($content)->lines()->each(function ($row) {
$data = str($row)->explode(':');
// do something with $data here
});
// instead of
$lines = preg_split('/\r\n|\n|\r/', $content);
foreach($lines as $line) {
$data = explode(':', $line);
// do something with $data here
}
$string = new Laraplus\String\StringBuffer('Hello world!');
// or
$string = str('Hello world!');
// a string "Hello world" is produced in all examples below
str('hello world')->ucfirst()->get();
(string)str('hello world')->ucfirst();
str('hello')->ucfirst() . ' world!';
str('hello world')->words()->each(function($word){
// Be careful, $word is just a plain string here.
// To convert it to StringBuffer again just call: str($word)
});
// result: 'hello the world...'
str('Hello the world of PHP!')->limitWords(3);
// result: 'hello the world etc.'
str('Hello the world of PHP!')->limitWords(3, ' etc.');
// result: 'world'
str('Hello the world of PHP!')->wordAt(2);