Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ladder_raw = file_get_contents('ftp://path/to/ladder.txt');
- $ladder = [];
- foreach(explode("\n", $ladder_raw) as $line)
- {
- $pos = 0;
- $entry[0] = extractNonBlankString($line, $pos);
- $entry[1] = extractNonBlankString($line, $pos);
- $ladder[] = [ $entry[0], trim($entry[1]) ];
- }
- ?>
- <table>
- <?php
- foreach($ladder as $entry)
- {
- ?>
- <tr>
- <td style="padding: 5px;"><?=$entry[1]?></td>
- <td style="padding: 5px;"><?=$entry[0]?></td>
- </tr>
- <?php
- }
- ?>
- </table
- <?php
- function extractNonBlankString($str, &$pos)
- {
- if ($pos > strlen($str))
- return "";
- $toReturn = "";
- while (($pos < strlen($str)) && isBlank($str[$pos]))
- {
- $pos++;
- }
- if ($pos > strlen($str))
- return "";
- while (($pos < strlen($str)) && !isBlank($str[$pos]))
- {
- $toReturn .= $str[$pos++];
- }
- if ($pos > strlen($str))
- return "";
- return $toReturn;
- }
- //!< extracts substring without spaces from that position
- function isBlank($str)
- {
- if (!isset($str)) return true;
- if ($str == "") return true;
- if ($str == " ") return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement