Skip to content

Instantly share code, notes, and snippets.

@gowon
Last active December 22, 2015 18:09
Show Gist options
  • Save gowon/6511094 to your computer and use it in GitHub Desktop.
Save gowon/6511094 to your computer and use it in GitHub Desktop.
Quick and dirty lipsum-type generator. Throws random letters together to create paragraphs.
<?php
function gibberish($numParagraphs = 1, $wordsPerParagragh = 10, $maxWordLength = 20)
{
mt_srand(microtime() * 1000000);
$bank = array_merge(range('a', 'z'), range('A', 'Z'));
$paragraphs = array();
for ($i = 0; $i < $numParagraphs; $i++)
{
$words = array();
for ($j = 0; $j < $wordsPerParagragh; $j++)
{
shuffle($bank);
$word = implode($bank);
$length = mt_rand(3, $maxWordLength);
$words[] = substr($word, 0, $length);
}
$paragraphs[] = implode(' ', $words);
}
return '<p>'.implode(".</p>\n\n<p>", $paragraphs).'.</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment