Get current weather forecast using PHPQuery

December 17th, 2013 by Alex Leave a reply »
// load PHPQuery
require_once 'phpquery.php';
// load URL and parse it with PHPQuery
$html = file_get_contents('');
// and now just output the data
foreach(pq('#feed-main') as $feed) {
  echo 'Condition: '.pq($feed)->find('.cond')->text() . '<br />';
  echo 'Temperature: '.pq($feed)->find('.temp')->text() . '<br />';

This would output something like

Condition: Light Fog <br />
Temperature: 1° <br />

If you get a “Fatal error: Uncaught exception ‘Exception’ with message ‘Error loading XML markup’” then you are probably trying to load an XHTML document with phpQuery::newDocumentHTML or opposite. Just try using phpQuery::newDocumentXHTML or phpQuery::newDocumentXML.

Comments are closed.