public Random::sentences($min_word_count, $capitalize = FALSE)
Generates sentences Latin words, often used as placeholder text.
Parameters
int $min_word_count: The minimum number of words in the return string. Total word count can slightly exceed provided this value in order to deliver sentences of random length.
bool $capitalize: Uppercase all the words in the string.
Return value
string Nonsense latin words which form sentence(s).
File
- core/lib/Drupal/Component/Utility/Random.php, line 192
Class
- Random
- Defines a utility class for creating random data.
Namespace
Drupal\Component\Utility
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | public function sentences( $min_word_count , $capitalize = FALSE) { $dictionary = array ( "abbas" , "abdo" , "abico" , "abigo" , "abluo" , "accumsan" , "acsi" , "ad" , "adipiscing" , "aliquam" , "aliquip" , "amet" , "antehabeo" , "appellatio" , "aptent" , "at" , "augue" , "autem" , "bene" , "blandit" , "brevitas" , "caecus" , "camur" , "capto" , "causa" , "cogo" , "comis" , "commodo" , "commoveo" , "consectetuer" , "consequat" , "conventio" , "cui" , "damnum" , "decet" , "defui" , "diam" , "dignissim" , "distineo" , "dolor" , "dolore" , "dolus" , "duis" , "ea" , "eligo" , "elit" , "enim" , "erat" , "eros" , "esca" , "esse" , "et" , "eu" , "euismod" , "eum" , "ex" , "exerci" , "exputo" , "facilisi" , "facilisis" , "fere" , "feugiat" , "gemino" , "genitus" , "gilvus" , "gravis" , "haero" , "hendrerit" , "hos" , "huic" , "humo" , "iaceo" , "ibidem" , "ideo" , "ille" , "illum" , "immitto" , "importunus" , "imputo" , "in" , "incassum" , "inhibeo" , "interdico" , "iriure" , "iusto" , "iustum" , "jugis" , "jumentum" , "jus" , "laoreet" , "lenis" , "letalis" , "lobortis" , "loquor" , "lucidus" , "luctus" , "ludus" , "luptatum" , "macto" , "magna" , "mauris" , "melior" , "metuo" , "meus" , "minim" , "modo" , "molior" , "mos" , "natu" , "neo" , "neque" , "nibh" , "nimis" , "nisl" , "nobis" , "nostrud" , "nulla" , "nunc" , "nutus" , "obruo" , "occuro" , "odio" , "olim" , "oppeto" , "os" , "pagus" , "pala" , "paratus" , "patria" , "paulatim" , "pecus" , "persto" , "pertineo" , "plaga" , "pneum" , "populus" , "praemitto" , "praesent" , "premo" , "probo" , "proprius" , "quadrum" , "quae" , "qui" , "quia" , "quibus" , "quidem" , "quidne" , "quis" , "ratis" , "refero" , "refoveo" , "roto" , "rusticus" , "saepius" , "sagaciter" , "saluto" , "scisco" , "secundum" , "sed" , "si" , "similis" , "singularis" , "sino" , "sit" , "sudo" , "suscipere" , "suscipit" , "tamen" , "tation" , "te" , "tego" , "tincidunt" , "torqueo" , "tum" , "turpis" , "typicus" , "ulciscor" , "ullamcorper" , "usitas" , "ut" , "utinam" , "utrum" , "uxor" , "valde" , "valetudo" , "validus" , "vel" , "velit" , "veniam" , "venio" , "vereor" , "vero" , "verto" , "vicis" , "vindico" , "virtus" , "voco" , "volutpat" , "vulpes" , "vulputate" , "wisi" , "ymo" , "zelus" ); $dictionary_flipped = array_flip ( $dictionary ); $greeking = '' ; if (! $capitalize ) { $words_remaining = $min_word_count ; while ( $words_remaining > 0) { $sentence_length = mt_rand(3, 10); $words = array_rand ( $dictionary_flipped , $sentence_length ); $sentence = implode( ' ' , $words ); $greeking .= ucfirst( $sentence ) . '. ' ; $words_remaining -= $sentence_length ; } } else { // Use slightly different method for titles. $words = array_rand ( $dictionary_flipped , $min_word_count ); $words = is_array ( $words ) ? implode( ' ' , $words ) : $words ; $greeking = ucwords( $words ); } return trim( $greeking ); } |
Please login to continue.