PHP code example of bert-w / typomaniac

1. Go to this page and download the library: Download bert-w/typomaniac 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/ */

    

bert-w / typomaniac example snippets


$typomaniac = new \BertW\Typomaniac\Typomaniac([
    // Chance of an error (0 - 100), decided per character (default).
    'chance' => 2,
    // Usable mistakes (default).
    'mistakes' => [
        BertW\Typomaniac\Mistakes\CharacterAccents::class,
        BertW\Typomaniac\Mistakes\CharacterRepeat::class,
        BertW\Typomaniac\Mistakes\CharactersFlip::class,
        BertW\Typomaniac\Mistakes\CharacterSkip::class,
        BertW\Typomaniac\Mistakes\KeyboardTypo::class,
        BertW\Typomaniac\Mistakes\CharacterChangeCapitalization::class,
    ],
]);

$result = $typomaniac->typo('Please create random typo\'s in this text. The longer the text the more chance of an error!');

echo $result;

// Result:
// 'Please create randoom typo's in tihs text. The longer the text the more chance of an  error!'

class Result {
    /** @var array List of used mistakes and their frequency. */
    public $usedMistakes = [];

    /** @var array List of available mistakes. */
    public $mistakes = [];

    /** @var int The chance of a mistake (0 - 100). */
    public $chance;
}

// Add a mistake to the default mistake options (or assign it in the constructor).
$typomaniac->addMistake(\MyLibrary\FindSynonym::class);
$result = $typomaniac->typo(...);