04/05/18 - Loading Random Pages in "Context"
Hello,

Working on a project called "Kiosk Mode" to display live information on an information Kiosk much like people see in an airport. One of the challenges is streaming real time data from a reputable weather source like weather.gov. Using an "App" or third party tool creates the potential for failure and users will then see something like "error, unavailable" or having to pay a fee and dealing with a middle man.

So, here is the php solution to get the temperature and visibility direct from weather.gov. This method can also be used on XML or RSS feeds. Note the "method" and "header" being sent with the "$options" array". The script below is accessssing "weather.gov" using "GET" and that it is "Mozilla/59.0". The data the php code is requesting is the Airport code "KSFO" (San Franscisco Airport). The last four lines using "explode()" are just pulling the actual numbers we want rather than the entire page.

-A

	$options = array(
	  'http'=>array(
		'method'=>"GET",
		'header'=>"Accept-language: en\r\n" .
				  "Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
				  "User-Agent: Mozilla/59.0\r\n"
	  )
	);

	$context = stream_context_create($options);

	$url = "http://w1.weather.gov/xml/current_obs/display.php?stid=KSFO;

	$page = file_get_contents($url, false, $context);

	$temp1 = explode("", $page);

	$temp1 = explode("", $temp1[1])[0];

	$vis1 = explode("", $page);

	$vis1 = explode("", $vis1[1])[0];