2017-02-27 10 views
0

私のyahoo weather apiからcdataで説明を抽出しようとしたときに問題が発生しました。問題は正確なパスを見つけるかもしれないと思います。yahoo weather apiからdescriptionタグを抽出できません

<?php 
 
\t $url ="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(55844479)%20where%20text%3D%22Riga%2C%20Lv%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; 
 
\t $error = ""; 
 
\t $file = fopen($url, "r"); 
 
\t 
 
\t if($file == false) 
 
\t { 
 
\t \t $error = "File open error"; 
 
\t } 
 
\t else 
 
\t { 
 
\t \t $stringXML = ""; 
 
\t \t while (feof($file)==false) 
 
\t \t { 
 
\t \t \t $stringXML.= fread($file, 8192); 
 
\t \t } 
 
\t \t $xml = new SimpleXMLElement($stringXML); 
 
\t \t fclose($file); 
 

 
\t \t $description = $xml->results->link->description; 
 

 
\t } 
 
?> 
 

 

 
<html> 
 
\t <head> 
 
\t \t <title>Yahoo weather API</title> 
 
\t </head> 
 
\t <body> 
 
\t 
 
\t \t <h1>Yahoo weather api</h1> 
 
<?php 
 

 
\t if($error == "") 
 
\t { 
 
\t \t echo "<h3>Description:".$description."</h3>"; 
 
\t } 
 
\t else 
 
\t { 
 
\t echo "<p>".$error."</p>"; 
 
\t } 
 

 
?> \t 
 
\t </body> 
 
</html>

誰もの心私を助けて? :)

答えて

2

説明はリンクにありません。用途:

$description = $xml->results->channel->description; 

項目タグの内部CDATAと説明を取得するには、使用:

$description = $xml->results->channel->item->description; 
+0

ありがとうございます!しかし、私は2番目のdescriptionタグ、cdataを含むものが必要です:) –

+1

これは* item *の中にありますので$ description = $ xml-> results-> channel-> item-> descriptionとなります。編集@RalfsR – eeetee

+0

をご覧ください。 –

関連する問題