navisborealis / wonderwords-php
Generate random words and sentences with ease in PHP.
v1.0.0
2023-11-07 23:06 UTC
Requires
- php: ^7.1 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- php-coveralls/php-coveralls: dev-master
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^7.5 || ^8.5 || ^9.6
README
Wonderwords PHP
Generate random words, phrases and sentences with ease in PHP.
Installation
To install the package, run the following command:
composer require navisborealis/wonderwords-php
Usage
With this library you can generate:
- words - adjectives, nouns or verbs
- phrases - 1+ adjective and 1+ noun, like
Blushing Inspection
- sentences - this feature is still in development
Phrases
Basic structure of the phrase is adjective noun
. You can change:
- string separator, default
- number of adjectives and nouns, default
1
, - function used to modify the letters case, default
ucwords()
.
To use your own list of words see Changing default word list.
phrase( string $separator = ' ', int $numAdjectives = 1, int $numNouns = 1, callable $stringCaseFunction = null)
Generic, two word, space separated phrase
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; echo WonderWordsGenerator::phrase(); // Output: Blushing Inspection
Custom separator
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; echo WonderWordsGenerator::phrase('-'); // Output: Blushing-Inspection
Different number of adjectives and nouns
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; echo WonderWordsGenerator::phrase(' ', 2, 3); // Output: Receptive Weary Disease Motive Vegetarian
Custom function to change letters casing
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; echo WonderWordsGenerator::phrase(' ', 1, 1, 'strtoupper'); // Output: BLUSHING INSPECTION
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; echo WonderWordsGenerator::phrase(' ', 1, 1, function ($phrase) { return ucfirst($phrase); }); // Output: Blushing inspection
Words
Generating words
From each category (Adjective
, Noun
, Verb
) you can generate a single word:
use NavisBorealis\WonderwordsPhp\Words\Adjective; echo Adjective::randomWord(); // Output: various
or an array of words:
use NavisBorealis\WonderwordsPhp\Words\Adjective; $words = Adjective::randomWords(5); // ["innate", "noiseless", "screeching", "sloppy", "squeamish"]
Changing default word list
For each word category (Adjective
, Noun
, Verb
) you can change the default word list:
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; use NavisBorealis\WonderwordsPhp\Words\Adjective; Adjective::setWordList(['customadjective1', 'customadjective2']); echo WonderWordsGenerator::phrase(); // Output: Customadjective2 Inspection
also, you can reset word list to its defaults:
use NavisBorealis\WonderwordsPhp\WonderWordsGenerator; use NavisBorealis\WonderwordsPhp\Words\Adjective; Adjective::setWordList(['customadjective1', 'customadjective2']); echo WonderWordsGenerator::phrase(); // Output: Customadjective2 Inspection Adjective::reset(); echo WonderWordsGenerator::phrase(); // Output: Scientific Inspection
Sentences
In development...
Credits
Wonderwords PHP is based on wonderwordsmodule
python module and has been made possible thanks to the following works:
wonderwordsmodule
for python under the MIT Licenseprofanitylist.txt
from RobertJGabriel/Google-profanity-words under the Apache-2.0 license- PhraseGenerator under the MIT License
- word-generator under the MIT license