开发者

simplexml load on google weather api prooblem

开发者 https://www.devze.com 2023-02-22 15:00 出处:网络
Hi I have been having problems with the google weather api having errors Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 开发者_StackOverflow中文版2: parser error ....

Hi I have been having problems with the google weather api having errors Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 开发者_StackOverflow中文版2: parser error ....

I tried to use the script of the main author(thinking it was my edited script) but still I am having this errors I tried 2 //komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/

and

//tips4php.net/2010/07/local-weather-with-php-and-google-weather/

The weird part is sometimes it fixes itself then goes back again to the error I have been using it for months now without any problem, this just happened yesterday. Also the demo page of the authors are working but I have the same exact code any help please.

this is my site http://j2sdesign.com/weather/widgetlive1.php

@Mike I added your code

<?
$xml = file_get_contents('http://www.google.com/ig/api?weather=jakarta');  if (!     simplexml_load_string($xml)) {   file_put_contents('malformed.xml', $xml); }
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");

?>

and made a list of the error but I can't seem to see the error cause it's been fixing itself then after sometime goes back again to the error

here is the content of the file

<?php  include_once('simple_html_dom.php');  // create doctype $dom = new DOMDocument("1.0");  
// display document in browser as plain text 
// for readability purposes //header("Content-Type: text/plain");  
// create root element 
$xmlProducts = $dom->createElement("products"); 
$dom->appendChild($xmlProducts);  
$pages = array(     'http://myshop.com/small_houses.html',     'http://myshop.com/medium_houses.html',     'http://myshop.com/large_houses.html' )   foreach($pages as $page) {     $product = array();     $source = file_get_html($page);      foreach($source->find('img') as $src)     {         if (strpos($src->src,"http://myshop.com") === false)         {             $product['image'] = "http://myshop.com/$src->src";         }     }      foreach($source->find('p[class*=imAlign_left]') as $description)     {         $product['description'] =  $description->innertext;     }      foreach($source->find('span[class*=fc3]') as $title)     {         $product['title'] =  $title->innertext;     }      //debug perposes!      echo "Current Page: " . $page . "\n";     print_r($product);     echo "\n\n\n"; //Clear seperator } ?>


When simplexml_load_string() fails you need to store the data you're trying to load somewhere for review. Examining the data is the first step to diagnose what it causing the error.

$xml = file_get_contents('http://example.com/file.xml');

if (!simplexml_load_string($xml)) {
  file_put_contents('malformed.xml', $xml);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消