Html Strip

<?php
/*  
	Airnow Web Page Scraper
	Language: PHP
	Author: Tom Igoe modified by Michael Luck Schneider
*/
	//Define variables:
	//url of the page with the temperature for Brooklyn
	$url = 'http://www.nytimes.com/gst/weather.html?detail=155660';
	$readTemp = 0; 	//flag telling tou the next line is the temp
	$temp = -1;	//the particle value

	//open the file at the URL for reading
	$filePath = fopen ($url, "r");

	//while you have not reached the end of the file
	while (!feof($filePath)){
		//read one line at a time and strip HTML and PHP
		$line = fgetss($filePath, 4096);
		//echo "line read";
		//if the previous line was the current conditions
		//$readTemp should equal 1 and you gotta grab the temp
		//save in $temp 
		if ($readTemp == 1) {
			$temp = strtok($line, "&");
			echo "Temperature<$temp>";
			$readTemp = 0;
		}
		//if the current line cuntains substring "Current Conditions""
		//the following line is the temperature set marker variable
		if (preg_match('/Current Conditions/', $line )) {
			//echo "<current tecmp found>";
			if ($temp == -1){
				$readTemp = 1;
			}
		}
	}
	//close the file at the URL when you are done
	fclose($filePath);
?>
  Edit | View | History | Print | Recent Changes | Search Page last modified on September 25, 2007, at 09:32 PM