Advertisement
vertrex

HR - Leaderboard Script

Sep 11th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. $ladder_raw = file_get_contents('ftp://path/to/ladder.txt');
  3.  
  4. $ladder = [];
  5.  
  6. foreach(explode("\n", $ladder_raw) as $line)
  7. {
  8.     $pos = 0;
  9.     $entry[0] = extractNonBlankString($line, $pos);
  10.     $entry[1] = extractNonBlankString($line, $pos);
  11.     $ladder[] = [ $entry[0], trim($entry[1]) ];
  12. }
  13.  
  14. ?>
  15. <table>
  16. <?php
  17. foreach($ladder as $entry)
  18. {
  19.     ?>
  20.     <tr>
  21.         <td style="padding: 5px;"><?=$entry[1]?></td>
  22.         <td style="padding: 5px;"><?=$entry[0]?></td>
  23.     </tr>
  24.     <?php
  25. }
  26. ?>
  27. </table
  28. <?php
  29.  
  30. function extractNonBlankString($str, &$pos)
  31. {
  32.     if ($pos > strlen($str))
  33.         return "";
  34.  
  35.     $toReturn = "";
  36.  
  37.     while (($pos < strlen($str)) && isBlank($str[$pos]))
  38.     {
  39.         $pos++;
  40.     }
  41.  
  42.     if ($pos > strlen($str))
  43.         return "";
  44.  
  45.     while (($pos < strlen($str)) && !isBlank($str[$pos]))
  46.     {
  47.         $toReturn .= $str[$pos++];
  48.     }
  49.  
  50.     if ($pos > strlen($str))
  51.         return "";
  52.  
  53.     return $toReturn;
  54. }
  55.  
  56. //!<  extracts substring without spaces from that position
  57. function isBlank($str)
  58. {
  59.     if (!isset($str)) return true;
  60.  
  61.     if ($str == "") return true;
  62.  
  63.     if ($str == " ") return true;
  64.  
  65.     return false;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement