0) { sleep($delay); } # read file if (!file_exists($BOOKS_FILE)) { header("HTTP/1.1 500 Server Error"); die("ERROR 500: Server error - Unable to read input file: $BOOKS_FILE"); } # ought to use DOMDocument, but oh well header("Content-type: application/xml"); print "\n"; if ($category) { print "\n"; foreach (file($BOOKS_FILE) as $line) { # Bachelor Chow in 20 Minutes|Gloria Demartelaere|cooking|2005|30.00 list($title, $author, $book_category, $year, $price) = explode("|", trim($line)); if ($book_category == $category) { # print it as XML print "\t\n"; print "\t\t$title\n"; print "\t\t$author\n"; print "\t\n"; } } print "\n"; } else { print "\n"; $categories = array(); foreach (file($BOOKS_FILE) as $line) { list($title, $author, $book_category, $year, $price) = explode("|", trim($line)); if (!isset($categories[$book_category])) { $categories[$book_category] = 1; } } ksort($categories); foreach ($categories as $book_category => $useless) { print "\t$book_category\n"; } print "\n"; } ?>