<?php
  function printLinks(){
    if(!($fd = fopen("links.txt", "r"))){
      echo "Lista odnośników jest w tej chwili niedostępna.";
    }
    else{
      echo "<ul>";
      while (!feof ($fd)){
        $line = trim(fgets($fd));
        if(!($pos = strpos($line, ' '))){
          $link = $line;
          $desc = $line;
        }
        else{
          $link = substr($line, 0, $pos);
          $desc = substr($line, $pos + 1);
        }
        if($link != "" && $desc != ""){
          echo "<li><a href=\"$link\">$desc</a></li>";
        }
      }
      fclose($fd);
      echo "</ul>";
    }
  }
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Moja strona WWW</title>
  </head>
  <body>
    <div>
    <?php
      printLinks();
    ?>
    </div>
  </body>
</html>
