Sample Solution

Example 13.8. One Possible Solution Is

<?php
    $file = 'firmaFront.txt';
    $linksFile = "firmaFrontLinks.txt";

    $fpa = fopen($linksFile, "r") or die("Linksfile not found");    // for navigation menu

    $fp = fopen($file, "r") or die("File not found");               // front page content
    $name = fgets($fp, 4096) or die("UPS1");    // line 1
    $tagl = fgets($fp, 4096) or die("UPS2");    // line 2
    $logo = fgets($fp, 4096) or die("UPS3");    // line 3


    $title = "PHP Workshop Case - " . $tagl;
    include "xhtmlTop.inc.php";
?>
    <link rel="stylesheet" type="text/css" href="phpWorkshop.css"/>
<?php
    include "xhtmlNeck.inc.php";
    print("<div id='body'>\n");                 // wrapper

    printf("<div id='logo'><img src='%s' alt='%s'/></div>\n", $logo, $tagl);
    printf("<div id='name'><h1>%s</h1></div>\n", $name);

    print("<div id='nav'>\n<ul>");              // nav with a list
    while (!feof($fpa)) {                       // loop fremaining lines into array
        $line = fgets($fpa, 4096);              // read line
        $link = explode(";", $line);            // explode into array
        if (count($link) == 2)                  // was line empty (not 2 elements)
            printf("<li><a href='%s'>%s</a></li>\n", $link[0], $link[1]);
    }                                           // print the link
    print("</ul>\n</div>\n");                   // end list and nav

    print("<div id='content'>\n");              // content
    while (!feof($fp)) {                        // loop fremaining lines into array
        $line = fgets($fp, 4096);               // read line
        printf("<p>%s</p>\n", $line);           // print as paragraph
    }
    print("</div>\n");                          // end content

    print("</div>\n");                          // end wrapper

    include "xhtmlFoot.inc.php";
?>