Name:

Hobby:

Data File Contains

Wrote to file."; fclose($hFile); } else { print "

Error. Couldn't write to file!"; // file could not be opened, so just don't do anything } } // ****** FUNCTION ****** // NAME: display_file_contents // PARAMETERS: none // PURPOSE: read all the data from the database and print it out in html function display_file_contents() { $filename = "data.txt"; $dir = "./"; $contents = file_get_contents($dir . $filename); $contents = explode("\n", $contents); print ""; print ""; print "
#NameHobby "; $cnt = 0; foreach ($contents as $line) { if ($line != "") { $line = explode(",", $line); print "
" . ($cnt + 1); for ($i = 0; $i < 2; $i++) { print "" . $line[$i]; } print "
"; print ""; print "
"; $cnt++; } } print "
"; } function remove_line_from_file($line_to_remove) { $filename = "data.txt"; $dir = "./"; if (file_exists($dir . $filename)) { // file exists can attempt to remove line $contents = explode("\n", file_get_contents($dir . $filename)); if ($hFile = fopen($dir . $filename, "w")) { // opened file, do the deed for ($i = 0; $i < sizeof($contents); $i++) { if ($i != $line_to_remove) { fwrite($hFile, $contents[$i]); if ($i < sizeof($contents) - 1) { fwrite($hFile, "\n"); } } } } else { // couldn't open file, there was a problem } } } ?>