2011-04-07 78 views
-1

嗨我一直有谷歌天氣api有問題的問題警告:simplexml_load_string()[function.simplexml-load-string]:實體:第2行:解析器錯誤....simplexml加載谷歌天氣api prooblem

我試圖使用主要作者的腳本(認爲這是我編輯的腳本),但我仍然有這個錯誤我嘗試了2 //komunitasweb.com/2009/09/showing-the-weather-with- PHP和 - 谷歌全天候-API/

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

奇怪的部分是有時它修復自己然後再次回到我已經使用它幾個月的錯誤現在沒有任何問題,這只是昨天發生。也作者的演示頁面正在工作,但我有相同的確切代碼,請幫助。

這是我的地盤http://j2sdesign.com/weather/widgetlive1.php

@Mike我加了你的代碼

<? 
$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"); 

?>

並提出了錯誤的清單,但我似乎無法看到錯誤原因它一直在修復自己然後再回到錯誤

這裏是文件的內容

<?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 } ?> 
+0

確定現在它的工作希望它保持這樣 – cooldude 2011-04-07 14:02:16

+0

錯誤又回來了,請幫助感謝 – cooldude 2011-04-07 14:11:04

+0

即使這樣一個不工作//www.ankitsharma.info/blog/weather-widget-using-google- weather-api我正在使用作者腳本http://j2sdesign.com/wg/wg/weatherg/documentation-and-example/這是我的託管問題嗎? – cooldude 2011-04-07 14:28:57

回答

2

simplexml_load_string()失敗時,您需要存儲您嘗試加載某處以供查看的數據。檢查數據是診斷導致錯誤的第一步。

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

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

@Mike:+1。錯誤正在被拋出,因爲返回的XML無效。 – 2011-04-07 14:54:59

+0

嗨,大家好,感謝您的回覆我只是想知道爲什麼它不在我的作者頁上工作我只是複製了他發佈的確切腳本,這是我的託管問題? – cooldude 2011-04-07 15:14:17

+0

@cooldude我們不能回答,直到我們發現問題是什麼。 – 2011-04-07 15:50:36