Yes... just remove the var_dump($info) line.
The reason I did that was so you can see how the array is set up. You can do this though:
<?php
$url = 'http://www.weatheroffice.ec.gc.ca/city/pages/on-11_metric_e.html';
$handle = fopen($url, "r");
$weather = file_get_contents($url);
fclose($handle);
/**
* Clean up the retrieved HTML code
*
* We clean up the source we got here. Basically, we only want a section
* of the code. We only need the working weather section. So we cut out
* the meat, starting at '<div id="citybanneradright" class="right">' and
* ending at '<div id="cityadditional">' which will give us just the info
* about the current conditions. Exactly what we want!!
*/
$weather = substr($weather, strpos($weather, '<div id="citybanneradright" class="right">'), (strpos($weather,'<div id="cityadditional">')-strpos($weather, '<div id="citybanneradright" class="right">')));
$weather = substr($weather, strpos($weather, '<h1>'), ((strpos($weather, '</dl>')-strpos($weather, '<h1>'))+5));
/**
* PERL RegEx Pattern to match
*
* The pattern of what the HTML will look like each time that page is hit
* by us (or any other viewer). We define areas with parenthesis "()"
* and what their values can contain with ranges "[a-zA-Z]".
* Research Regular Expressions if you don't understand.
*/
$pattern = "@<h1>[\s\n]*<a name=\"content\"> </a>([\w\s\-.]*)</h1>[\s\n]*<div id=\"city\">[\s\n]*<div id=\"box\">[\s\n]*<div id=\"citycurrent\">[\s\n]*<h2>Currently</h2>[\s\n]*<div id=\"cityobserved\">([\w\-\s\:]*)</div>[\s\n]*<dl>[\s\n]*<dt>Temperature</dt>[\s\n]*<dd>([\d\-.]*) °([F|C]{1})</dd>[\s\n]*<dd class=\"dd1\"/>[\s\n]*<dt>Pressure/ Tendency</dt>[\s\n]*<dd>([\d\.\-]*) kPa<span class=\"([\w]*)\" id=\"[\w]*\">[\w&;]*</span></dd>[\s\n]*<dd class=\"dd1\"/>[\s\n]*<dt>Humidity</dt>[\s\n]*<dd>([\d\-.]*) %</dd>[\s\n]*<dd class=\"dd1\"/>[\s\n]*<dt>Dewpoint</dt>[\s\n]*<dd>([\d\-]*) °([F|C]{1})</dd>[\s\n]*<dd class=\"dd1\"/>[\s\n]*<dt>Wind</dt>[\s\n]*<dd>([\w\-\n\/\t\:\s.]*)</dd>[\s\n]*<dd class=\"dd1\"/>[\s\n]*</dl>@m";
preg_match($pattern, $weather, $info);
array_shift($info);
/**
* Define variable names.
*
* Each array element will become a variable name. You can use whatever
* naming scheme you wish, but this was easiest for me to understand.
*
* Variable names will be:
* $loc
* $obs
* $temp
* $temp_scale
* etc. . . .
*/
$var = array( 'loc', # Location
'obs', # Observation information
'temp', # Temperature
'temp_scale', # Temperature Scale (Celsius, Farenheit)
'barom', # Barometric Pressure
'barom_tend', # Barometric Pressure Tendency (rising, falling, steady)
'humidity', # Humidity
'dewpt', # Dew Point
'dew_scale', # Dew Point Scale (Celsius, Farenheit)
'wind' # Wind speed information
);
/**
* Extract information from preg_match array into custom variables.
*
* Loop through the array $info. Using the array key as a point of reference, we
* create a variable with the name that corresponds to the key in the array $var.
* From that, we give that new variable the value it is supposed to have.
*
* This is an alternative. You can use $info[0] -> $info[9] to reference these values
* as well. Either way will work. It's up to you.
*/
foreach($info as $key => $val)
{
$$var[$key] = $val;
}
// Echo out something about the weather....
echo 'Currently in '.$loc.' (<em>'.$obs.'</em>) it is <strong>'.$temp.' ° '.$temp_scale.'</strong>.<br>';
echo 'The barometric pressure is '.$barom.' and '.$barom_tend.' with '.$humidity.'% humidity. ';
echo 'The dew point is '.$dewpt.' °'.$dew_scale.'. Winds are '.$wind;
?>
Read my comments, they'll help you out.
~Brett