<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> 
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="3600; URL=http://127.0.0.1/sock1.php">
       <title>Title here!</title>
<?
	function myfget($filp){
		$ch = fgetc($filp);
		$retval = $ch;
		while (!feof($filp) && $ch!=">"){
			$ch = fgetc($filp);
			$retval = $retval.$ch;
		}
		return $retval;
	}
?>

</head>
<body>
	<?
		echo "Headlines from the NYTimes:<br>";
		$cnt1= 0;
		$spaces;
		$fp = fsockopen ("www.nytimes.com", 80, $errno, $errstr, 30);
		$fp2 = fopen("./headlines", "w"); //write headlines to a file
		if (!$fp) {
			echo "$errstr ($errno)<br>\n";
		} else {
			fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
			while (!feof($fp)) {
				$str1 = myfget ($fp);
				if (ereg("</strong>", $str1)){
					$str2 = ereg_replace("</strong>",".",$str1);
				} else { $str2=""; }
				$spaces = strlen($str2);
				if ($spaces == 0){
				//	echo $cnt1++.", ";
				} else {
					//echo $str2;
					if (strlen($str2) > 40){
					while (strlen($str2)<80){
						$str2 = $str2." ";
					}
				} else {
					while (strlen($str2)<40){
						$str2 = $str2." ";
					}
				}
				echo $str2;
				fputs($fp2, $str2);
			}
  		}
  		fclose ($fp);
		fclose($fp2);
	}
	echo "Socket closed.";
?>
</body>
</html>
