Advertisement
garfield

[PHP]Ranking System

Jul 24th, 2014
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.34 KB | None | 0 0
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><table border="1%" cellspacing="1" style="border-collapse: collapse;">
  2. <?php
  3.     //  Defina aqui aonde fica as contsa do servidor;
  4.     $PlayerDir   =  "contas/";
  5.    
  6.     // A função Opendir abre o diretório que você configurou acima;
  7.     $Diretorio   =  opendir($PlayerDir);
  8.    
  9.     // Criamos uma array para aramazenar a pontuação e o nome de cada player;
  10.     $Player      = Array();
  11.    
  12.    
  13.     // Procurando por todos os arquivos da pasta que você definiu ($PlayerDir).
  14.     while(false != ($Arquivo = readdir($Diretorio))){
  15.    
  16.         // Verificar se o arquivo tem a extensão .ini
  17.         if(strstr($Arquivo, ".ini")){
  18.        
  19.             // Armazenamos o arquivo encontrado na variável $getLinha
  20.             $getLinha = parse_ini_file($PlayerDir.$Arquivo);
  21.            
  22.            
  23.             // Armazena o nome do player em uma array com o score pegado da
  24.             // Variável acima($getLinha)
  25.             // Usamos substr para remover o ".ini" do nome.
  26.             $Player[substr($Arquivo, 0, -4)] = $getLinha["Score"];
  27.         }
  28.     }
  29.    
  30.    
  31.     // Classificamos as pontuações  usando uma função
  32.     // nativa que classifica arrays.
  33.     arsort($Player);
  34.    
  35.    
  36.     // Criamos a variável $Players para contar quantos players tem
  37.     $Players    = count($Player);
  38.    
  39.     // Fazemos um interador para
  40.     $Interador  = 0;
  41.    
  42.     // Criamos uma string com uma tabela simples
  43.     $Exibir     = "<table border='1%' cellspacing='1' style='border-collapse: collapse;'>";
  44.    
  45.     // Adicionamos há string uma identificação ("Nome","Pontuação").
  46.     $Exibir    .= '<tr><td style="background-color: lightblue;"><b>Posição</b></td> <td style="background-color: lightblue;"><b>Nick</b></td><td style="background-color: lightblue;"><b>Score</b></td></tr>';
  47.    
  48.     // Fazemos um loop pela quantidade de players achados na pasta
  49.    
  50.     $Position   = 0;
  51.    
  52.    
  53.     while($Players != $Interador){
  54.    
  55.         // Adicionamos uma linha na string $Exibir.
  56.        
  57.         if($Interador == 15){
  58.             break;
  59.         }
  60.        
  61.         $Format = "contas/".Key($Player).".ini";
  62.        
  63.         $Interador ++;
  64.        
  65.         $Exibir .= "<tr><td>$Interador</td><td>".Key($Player)."</td><td>".file_Get($Format, "Score")."</td></tr>";
  66.        
  67.         // Partimos para nosso próximo parâmetro na array $Player
  68.         next($Player);
  69.        
  70.         // Incrementamos o interador;
  71.        
  72.     }
  73.    
  74.     // Exibimos
  75.     echo $Exibir;
  76.    
  77. function file_Get($fPlayer,$tag)
  78. {
  79.  
  80.     $fIni = parse_ini_file($fPlayer);
  81.     return $fIni[$tag];
  82. }
  83. ?>
  84.  
  85. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement