PHP code example of thestringler / manipulator

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


Manipulator::make('Freak')->append(' Out!');
// Freak Out!

Manipulator::make('camelCase')->camelToSnake();
// camel_case

Manipulator::make('className')->camelToClass();
// ClassName

Manipulator::make('hello')->capitalize();
// Hello

Manipulator::make('i like toast!')->capitalizeEach();
// I Like Toast!

Manipulator::make('Some String')->custom(function ($string) {
    // This is just a sample, this can be achieved with existing methods,
    // But you can do whatever string manipulation you want here.
    return ucfirst(strtolower($string));
});
// Some string

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

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

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

Manipulator::make('Bob')->getPossessive();
// Bob's
Manipulator::make('Silas')->getPossessive();
// Silas'

Manipulator::make('&')->htmlEntities();
// &amp;

Manipulator::make('&amp;')->htmlEntitiesDecode();
// &

Manipulator::make('&<>')->htmlSpecialCharacters();
// &amp;&lt;&gt;

Manipulator::make('HELLO')->lowercaseFirst();
// hELLO

// Named constructor
Manipulator::make('string');

Manipulator::make('Hello')->pad(2, '!!', STR_PAD_RIGHT);
// Hello!!

Manipulator::make('is the one.')->prepend('Neo ');
// Neo is the one.

Manipulator::make('Potato')->pluralize();
// Potatoes

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

$cats = ['Whiskers'];
Manipulator::make('Cat')->pluralize($cats);
// Cat

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

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

Manipulator::make('Dog Gone')->remove('Gone');
// Dog

Manipulator::make('Hello!!')->removeSpecialCharacters();
// Hello
Manipulator::make('Hello!!')->removeSpecialCharacters(['!']);
// Hello!!

Manipulator::make('la')->repeat(3);
// lalala

Manipulator::make('Pickles are good.')->replace('good', 'terrible');
// Pickles are terrible.

Manipulator::make('Whoa!')->reverse();
// !aohW

Manipulator::make('snake_case')->snakeToCamel();
// snakeCase

Manipulator::make('class_name')->snakeToClass();
// ClassName

Manipulator::make('<i>Hello</i>')->stripTags();
// Hello

Manipulator::make('camel case')->toCamelCase();
// camelCase

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

Manipulator::make('LOWER')->toLower();
// lower

Manipulator::make('This is a slug!')->toSlug();
// this-is-a-slug

Manipulator::make('snake case')->toSnakeCase();
// snake_case

Manipulator::make('upper')->toUpper();
// UPPER

Manipulator::make('  trimmed  ')->trim();
// trimmed

Manipulator::make('  trimmed')->trimBeginning();
// trimmed

Manipulator::make('trimmed  ')->trimEnd();
// trimmed

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

Manipulator::make('hello%21')->urlDecode();
// hello!

Manipulator::make('hello!')->urlEncode();
// hello%21

Manipulator::make('hello')->toUpper()->reverse();
// OLLEH