The solution to my problem (Thanks to those who helped!):
if (isset($submit)) {
$html = file($url);
$fh = fopen("getsite.txt", "w+");
fwrite($fh, implode("\n", $html));
fclose($fh);
$fh = fopen("getsite.txt", "r");
$contents = fread($fh, filesize("getsite.txt"));
fclose($fh);
$matches = preg_match_all("/<a href=[^<]+<\/a>/",$contents,$result);
foreach ($result as $val) {
foreach ($val as $key=>$final_val) {
echo "$key: $final_val<br>";
}
echo "<br>";
}
} else {
echo "
<form method=\"post\" action=\"$PHP_SELF\">
<h1>Enter URL:</h1>
<input type=\"text\" size=\"50\" name=\"url\" value=\"http://\">
<input type=\"submit\" name=\"submit\" value=\" go \">
</form>";
}