2017-01-14 4 views
0

私のWordPressサイトでxmlを使用すると、画面には0が表示されます アイデアはありますか?ページがちょうどゼロに印刷 おかげで(下記のコード)xmlを私のWordPressサイトで解析すると、画面には0が表示されるだけです

<?php 
$xmlObject = 
"<?xml version='1.0' encoding='utf-8'?> 
<properties> 
    <property> 
    <listing-type>rental</listing-type> 
    <status>for rent</status> 
    </property> 
</properties>"; 

    $data = simplexml_load_string($xmlObject) or die("Our availabilities feed is temporarily unavailable. Please try again later"); 
     $from = $data->property->listing-type; 
     echo $from; 
?> 

答えて

0

ダッシュがlabel in PHPで許可されていないと空白になっています。 これはおそらくマイナスと解釈されます。これが中括弧と引用符で囲まれたプロパティ名を囲まないようにする。このように:

<?php 
    $data = simplexml_load_string($xmlObject) or die("Our availabilities feed is temporarily unavailable. Please try again later"); 
      $from = $data->property->{'listing-type'}; 
      echo $from; 
?> 
関連する問題