0

I want to display the "hiOutsideTemp" value from this html page: http://amira.meteokrites.gr/ZWNTANA.htm to my page. It's a temp value.

I'm using the following code:

<?php

require_once 'simple_html_dom.php';
$html_string = file_get_contents('http://amira.meteokrites.gr/ZWNTANA.htm');
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html_string);
libxml_clear_errors();
$xpath = new DOMXpath($dom);
$values = array();
$row = $xpath->query('//td[@id="/html/body/table/tbody/tr[7]/td[2]"]');
foreach($row as $value) {
    $values[] = trim($value->textContent);
}

echo '<pre>';
print_r($values);
?>

But i get no result. What shall i do?

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
koukou
  • 13
  • 1
  • 5
  • I would look into something like PHPQuery, instead of Dom & Xpath. But that is just my preference. Basically it lets you use Jquery like selectors. `$Doc->find('.hiOutsideTemp')->text()` etc. – ArtisticPhoenix Mar 29 '18 at 06:30
  • Cant you just use HTML iframe? – VK321 Mar 29 '18 at 06:38

1 Answers1

0

Looking at the content of the URL you have, it just seems to be a list of settings and not a HTML page (this is only displayed if you don't have the actual HTML file included). The content is something like...

imerominia="29/03/18";
ora=" 9:37";
sunriseTime=" 7:10";
sunsetTime="19:37";
ForecastStr=" Mostly cloudy and cooler.  Windy with possible wind shift to the W, NW, or N. ";
tempUnit="°C";
outsideTemp="9.3";
hiOutsideTemp="9.5";
hiOutsideTempAT=" 0:03";
lowOutsideTemp="6.2";
lowOutsideTempAT=" 4:24";
...

So you can just load it as though it's an ini file format and this gives you an associative array of the data.

$html_string = file_get_contents('http://amira.meteokrites.gr/ZWNTANA.htm');
$data = parse_ini_string($html_string);

echo $data["hiOutsideTemp"];  // outputs - 9.5
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55