2017-02-10 9 views
0

yahooの天気でAPI呼び出しを行っているときに、次のxmlが返されました。 $をエコーアウトすると、なぜ空白になるのですか?SimpleXMLでXMLファイルにアクセスできない

$endpoint = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D%20560743&diagnostics=true'; 


$xml = simplexml_load_file($endpoint) or die('failed to load xml'); 
$out = $xml -> query -> diagnostics -> publiclyCallable; 

echo $out; 

はXMLを返しました:

This XML file does not appear to have any style information associated with it. The document tree is shown below. 
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2017-02-10T11:54:56Z" yahoo:lang="en-US"> 

<diagnostics> 
    <publiclyCallable>true</publiclyCallable> 
    <url execution-start-time="1" execution-stop-time="7" execution-time="6">...</url> 
    <user-time>8</user-time> 
    <service-time>6</service-time> 
    <build-version>2.0.92</build-version> 
</diagnostics> 
<results>...</results> 
</query> 

答えて

0

$xmlとしてqueryを削除すでにそれを表しています。

$endpoint = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D%20560743&diagnostics=true'; 
$xml = simplexml_load_file($endpoint) or die('failed to load xml'); 
$out = $xml -> diagnostics -> publiclyCallable; 
echo $out; // `true` 
0

XMLが無効であると思われる、

に受信した文字列を渡す前に、最初の行を削除

simplexml_load_file()

機能

関連する問題