Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function rollDice($rolls = null, $lang){
- if($rolls == null || $rolls < 5){
- echo rand(1,6);
- exit();
- }
- $splitter = 5;
- $nums = [];
- $words = [];
- $int = null;
- $get = null;
- $tmpNum = null;
- $tmpWord = null;
- $v = null;
- switch($lang){
- case 'en': $get = file_get_contents('http://world.std.com/~reinhold/beale.wordlist.asc'); break;
- case 'no': $get = file_get_contents('https://0101.no/diceware/diceware_nb_NO.txt'); break;
- case 'dk': $get = file_get_contents('http://pastebin.com/raw/rFatW8up'); break;
- case 'se': $get = file_get_contents('http://x42.com/diceware/diceware-sv.txt'); break;
- case 'fi': $get = file_get_contents('http://users.ics.aalto.fi/kaip/noppaware/noppaware.txt'); break;
- case 'de': $get = file_get_contents('http://world.std.com/~reinhold/diceware_german.txt'); break;
- case 'nl': $get = file_get_contents('http://theworld.com/~reinhold/DicewareDutch.txt'); break;
- case 'fr': $get = file_get_contents('http://world.std.com/~reinhold/diceware.wordlist.asc'); break;
- case 'es': $get = file_get_contents('http://world.std.com/~reinhold/diceware_espanol/DW-Espanol-2.txt'); break;
- case 'it': $get = file_get_contents('http://www.taringamberini.com/downloads/diceware_it_IT/lista-di-parole-diceware-in-italiano/2/word_list_diceware_it-IT-2.txt'); break;
- case 'ru': $get = file_get_contents('http://ex7f.com/liste/diceware.ru.txt'); break;
- case 'tr': $get = file_get_contents('https://web.archive.org/web/20110716063648/http://dicewaretr.110mb.com/diceware_tr.txt'); break;
- default: $get = file_get_contents('http://world.std.com/~reinhold/beale.wordlist.asc');
- }
- for($i=0;$i<$rolls;$i++){
- $number = rand(1,6);
- $tmpNum .= $number;
- $int++;
- while($int == $splitter){
- $pattern = preg_quote($tmpNum, '/');
- // finalise the regular expression, matching the whole line
- $pattern = "/^.*$pattern.*\$/m";
- // search, and store all matching occurences in $matches
- $match = preg_match_all($pattern, $get, $tmpWord);
- if($match){
- array_push($nums, $tmpNum);
- $str = str_replace($tmpNum, '', $tmpWord);
- $word = str_replace($tmpNum, '', $str[0][0]);
- array_push($words, $word);
- $int = null;
- $tmpNum = null;
- }
- else{
- echo "No matches found";
- }
- }
- }
- $cWords = count($words);
- $cNums = count($nums);
- $i = 0;
- while($i < $cNums){
- echo '<div style="display: inline-block;margin-left: 20px">';
- echo $nums[$i].'<br />';
- echo $words[$i].'<br /><br />';
- echo '</div>';
- $i++;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment