Skip to content

Commit

Permalink
Add character generation to script
Browse files Browse the repository at this point in the history
  • Loading branch information
alexchantastic committed Jul 3, 2018
1 parent 8715c9b commit e0718e7
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,41 @@
$type = $argv[1];
$length = $argv[2];

if (!$length) {
$length = 1;
$length = $length ? $length : 1;

/**
* Characters
*
* Generates characters of lorem ipsum.
*
* @param integer $count how many characters to generate
* @return string generated lorem ipsum characters
*/
function characters($count) {
global $lipsum;

$character_count = 0;
$words_array = array();

while ($character_count < $count) {
$word = $lipsum->word();
$word_length = strlen($word);

$character_count += $word_length + count($words_array);

array_push($words_array, $word);
}

$words = implode(' ', $words_array);
$words = substr($words, 0, $count);

return $words;
}

if ($type === 'words') {
if ($type === 'characters') {
echo ucfirst(characters($length));
}
elseif ($type === 'words') {
echo ucfirst($lipsum->words($length));
}
elseif ($type === 'sentences') {
Expand Down

0 comments on commit e0718e7

Please sign in to comment.