PHP code example of thestringler-laravel / manipulator

1. Go to this page and download the library: Download thestringler-laravel/manipulator 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/ */

    

thestringler-laravel / manipulator example snippets


TheStringlerLaravel\Manipulator\ManipulatorServiceProvider::class

'Manipulator' => TheStringlerLaravel\Manipulator\ManipulatorFacade::class,

$string = manipulate('hello')->toUpper();

manipulate('Freak')->append(' Out!');
// Freak Out!

manipulate('camelCase')->camelToSnake();
// camel_case

manipulate('className')->camelToClass();
// ClassName

manipulate('hello')->capitalize();
// Hello

manipulate('i like toast!')->capitalizeEach();
// I Like Toast!

manipulate('hello')->eachCharacter(function($char) {
    return strtoupper($char);
});
// HELLO

manipulate('hello moto')->eachWord(function($word) {
    return strrev($word);
});
// ollehotom

manipulate('hello moto')->eachWord(function($word) {
    return strrev($word);
}, true);
// olleh otom

manipulate('Bob')->getPossessive();
// Bob's
manipulate('Silas')->getPossessive();
// Silas'

manipulate('&')->htmlEntities();
// &amp;

manipulate('&amp;')->htmlEntitiesDecode();
// &

manipulate('&<>')->htmlSpecialCharacters();
// &amp;&lt;&gt;

manipulate('HELLO')->lowercaseFirst();
// hELLO

manipulate('Hello')->pad(2, '!!', STR_PAD_RIGHT);
// Hello!!

manipulate('is the one.')->prepend('Neo ');
// Neo is the one.

manipulate('Potato')->pluralize();
// Potatoes

$dogs = ['Zoe', 'Spot', 'Pickles'];
manipulate('Dog')->pluralize($dogs);
// Dogs

$cats = ['Whiskers'];
manipulate('Cat')->pluralize($cats);
// Cat

manipulate('Wordpress')->nthCharacter(5, function($character) {
    return mb_strtoupper($character);
});
// WordPress

manipulate('Oh hello there!')->nthWord(2, function($word) {
    return mb_strtoupper($word);
});
// Oh HELLO there!

manipulate('Dog Gone')->remove('Gone');
// Dog

manipulate('Hello!!')->removeSpecialCharacters();
// Hello
manipulate('Hello!!')->removeSpecialCharacters(['!']);
// Hello!!

manipulate('la')->repeat(3);
// lalala

manipulate('Pickles are good.')->replace('good', 'terrible');
// Pickles are terrible.

manipulate('Whoa!')->reverse();
// !aohW

manipulate('snake_case')->snakeToCamel();
// snakeCase

manipulate('class_name')->snakeToClass();
// ClassName

manipulate('<i>Hello</i>')->stripTags();
// Hello

manipulate('camel case')->toCamelCase();
// camelCase

manipulate('Hack The Planet!')->toL33t();
// (-)@{|< +/-/€ |O7@|\|€][!

manipulate('LOWER')->toLower();
// lower

manipulate('This is a slug!')->toSlug();
// this-is-a-slug

manipulate('snake case')->toSnakeCase();
// snake_case

manipulate('upper')->toUpper();
// UPPER

manipulate('  trimmed  ')->trim();
// trimmed

manipulate('  trimmed')->trimBeginning();
// trimmed

manipulate('trimmed  ')->trimEnd();
// trimmed

manipulate('This is a sentence and will be truncated.')->truncate(10, '...');
// This is a ...

manipulate('hello%21')->urlDecode();
// hello!

manipulate('hello!')->urlEncode();
// hello%21

manipulate('hello')->toUpper()->reverse();
// OLLEH