Guest User

Untitled

a guest
Jul 20th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. function rollDice($rolls = null, $lang){
  4.     if($rolls == null || $rolls < 5){
  5.         echo rand(1,6);
  6.         exit();
  7.     }
  8.  
  9.     $splitter = 5;
  10.  
  11.     $nums = [];
  12.     $words = [];
  13.  
  14.     $int = null;
  15.     $get = null;
  16.     $tmpNum = null;
  17.     $tmpWord = null;
  18.  
  19.     $v = null;
  20.  
  21.     switch($lang){
  22.         case 'en': $get = file_get_contents('http://world.std.com/~reinhold/beale.wordlist.asc'); break;
  23.         case 'no': $get = file_get_contents('https://0101.no/diceware/diceware_nb_NO.txt'); break;
  24.         case 'dk': $get = file_get_contents('http://pastebin.com/raw/rFatW8up'); break;
  25.         case 'se': $get = file_get_contents('http://x42.com/diceware/diceware-sv.txt'); break;
  26.         case 'fi': $get = file_get_contents('http://users.ics.aalto.fi/kaip/noppaware/noppaware.txt'); break;
  27.         case 'de': $get = file_get_contents('http://world.std.com/~reinhold/diceware_german.txt'); break;
  28.         case 'nl': $get = file_get_contents('http://theworld.com/~reinhold/DicewareDutch.txt'); break;
  29.         case 'fr': $get = file_get_contents('http://world.std.com/~reinhold/diceware.wordlist.asc'); break;
  30.         case 'es': $get = file_get_contents('http://world.std.com/~reinhold/diceware_espanol/DW-Espanol-2.txt'); break;
  31.         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;
  32.         case 'ru': $get = file_get_contents('http://ex7f.com/liste/diceware.ru.txt'); break;
  33.         case 'tr': $get = file_get_contents('https://web.archive.org/web/20110716063648/http://dicewaretr.110mb.com/diceware_tr.txt'); break;
  34.         default: $get = file_get_contents('http://world.std.com/~reinhold/beale.wordlist.asc');
  35.     }
  36.  
  37.     for($i=0;$i<$rolls;$i++){
  38.            
  39.             $number = rand(1,6);
  40.  
  41.             $tmpNum .= $number;
  42.            
  43.             $int++;
  44.  
  45.         while($int == $splitter){
  46.  
  47.             $pattern = preg_quote($tmpNum, '/');
  48.             // finalise the regular expression, matching the whole line
  49.             $pattern = "/^.*$pattern.*\$/m";
  50.             // search, and store all matching occurences in $matches
  51.             $match = preg_match_all($pattern, $get, $tmpWord);
  52.             if($match){
  53.  
  54.                 array_push($nums, $tmpNum);
  55.                 $str = str_replace($tmpNum, '', $tmpWord);
  56.                 $word = str_replace($tmpNum, '', $str[0][0]);
  57.                 array_push($words, $word);
  58.  
  59.                $int = null;
  60.                $tmpNum = null;
  61.             }
  62.             else{
  63.                echo "No matches found";
  64.             }
  65.            
  66.         }
  67.     }
  68.  
  69.     $cWords = count($words);
  70.     $cNums = count($nums);
  71.  
  72.     $i = 0;
  73.  
  74.     while($i < $cNums){
  75.         echo '<div style="display: inline-block;margin-left: 20px">';
  76.         echo $nums[$i].'<br />';
  77.         echo $words[$i].'<br /><br />';
  78.         echo '</div>';
  79.         $i++;
  80.     }
  81. }
  82.  
  83. ?>
Add Comment
Please, Sign In to add comment