PHP code example of theroadbunch / string-bean

1. Go to this page and download the library: Download theroadbunch/string-bean 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/ */

    

theroadbunch / string-bean example snippets




use \RoadBunch\StringBean\UpperCaseWordsFormatter;

$formatter = new UpperCaseWordsFormatter();

/* Format a string */
echo $formatter->format('these.are_some-words_to uppercase');

/* Format a list of strings */
print_r($formatter->formatList('this will be upper case', 'and.so.will.this'));



use RoadBunch\StringBean\PrefixTrimmer;

$formatter = new PrefixTrimmer('This');

/* Trim a word off the front of a string */
echo $formatter->format('This is a string of words');

/* Trimmers are case-sensitive */
echo $formatter->format('this is a string of words');



use RoadBunch\StringBean\CombinationFormatter;
use RoadBunch\StringBean\SplitCamelCaseFormatter;
use RoadBunch\StringBean\UpperCaseWordsFormatter;
use RoadBunch\StringBean\AbstractFormatter;

$formatter = new CombinationFormatter(
    new SplitCamelCaseFormatter(),
    new UpperCaseWordsFormatter(),
    // feel free to create a formatter on the fly
    new class extends AbstractFormatter {
        public function format(string $subject) : string{
            return "~={$subject}=~";
        }
    }
);
echo $formatter->format('aStringToFormat');

print_r($formatter->formatList('aStringToFormat', 'wild'));



use RoadBunch\StringBean\AbstractFormatter;

class L33tSpeakFormatter extends AbstractFormatter
{
    public function format(string $subject): string
    {
        return str_ireplace(['T', 'E', 'A'], ['7', '3', '4'], strtoupper($subject));
    }
};

$formatter = new L33tSpeakFormatter();
echo $formatter->format('leet speak');