Ki akarjuk bányászni egy időjárásjelentő oldalról hogy hány fok van, hány fok lesz, stb.
/**
* $source szovegbol kibanyassza a
* $id id-ju div erteket es
* $type tipusra castolva visszaadja
*/
function get_value_by_div_id($source, $id, $type) {
$matches = array();
$regexp = "<div.*?id\=\"$id\".*?>(.*?)<\/div>";
preg_match("/$regexp/s", $source, $matches);
settype($matches[1], $type);
return $matches[1];
}
Így pl.
26&deg;C
...
28&deg;C
...';
$t = get_value_by_div_id($source, "current_temps", 'int');
$e = get_value_by_div_id($source, "current_rfval", 'int');
echo "Hőmérséklet $t fok (érzésre $e)";A kimeneten:
Hőmérséklet: 26 fok (érzésre 28 fok).