<?

	$file_name = "/home/abu-jeib/temp/homepages2.txt";
	$a = array();
        @ $f = fopen($file_name,'r');
        if (!$f)
        {
		if (!file_exists($file_name))
			echo "File \"$file_name\" does not exist.<br>\n";
		else
        		echo "<h2 align=center>Can't open file
				 \"$file_name\" for reading.</h2><BR>\n";
                exit;
        }
	$b = array();
        $line = trim(fgets($f));
        while (!feof($f))
        {
        	if (!empty($line))
		{
			// Separate the name from the URL
			list($name,$url) = split(';',$line,2);

			/* Remove leading and trailing whitespace
			   from each the name and the URL.
			*/
                        $name = trim($name);
                        $url = trim($url);

			/*
		        Before sorting, make sure the capitalization is correct because
        		that will affect the sorting.
        		*/
			$name=ucwords(strtolower($name));

			/*
			Store the names in the indices of array b
			and make the URL's the values of b.
			*/
			$b[$name] = $url;
		}
                $line = trim(fgets($f));
        }
        fclose($f);	
	
	/* Sort b with respect to the indices (keys).
	Thus, the array will be sorted with respect to the
	name, which will be sorted with respect to the format
	"first_name middle_initial last_name".
	*/
	ksort($b);
	
	echo "<html><head></head><body>";
        echo "<h1 align=center>Student Homepages</h1><ol>\n";
	foreach ($b as $k => $v)
	{ 
			//echo $v, "<br>";
                        echo "<li><a href='$v'>$k</a>\n";
	}

	echo "</ol></body></html>";

?>
