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タグ、cdataを含むものが必要です:) –
これは* item *の中にありますので$ description = $ xml-> results-> channel-> item-> descriptionとなります。編集@RalfsR – eeetee
をご覧ください。 –