2012-03-27 6 views
0

tumblrブログの最新の投稿を私のウェブサイトに入れたいと思う。私はAPIから特定のタグを選択する方法を理解することはできません。tumblr APIで写真のサイズを選択する

XMLは、以下の構造を有する:

<tumblr> 
    <posts> 
     <post> 
      <photo-url max-width="500"> 
       image_500.jpg 
      </photo-url> 
      <photo-url max-width="250"> 
       image_250.jpg 
      </photo-url> 
     </post> 
    </posts> 
</tumblr> 

今どのように私はここ3行目に250バージョンをしたいことを指定することができますか?

<?php 
    $xmlResult = file_get_contents($tumblr_url_aktuell); 
    $xml = simplexml_load_file($tumblr_url_aktuell); 
    $image = $xml->posts->post->{'photo-url'} 
?> 

ありがとう!

答えて

0

必要なものを選択するには、それらをループする必要があります。

<?php 
    $xmlResult = file_get_contents($tumblr_url_aktuell); 
    $xml = simplexml_load_file($tumblr_url_aktuell); 
    foreach($xml->posts->post->{'photo-url'} as $photoURL){ 
     if((string)$photoURL['max-width'] == '250'){ 
      $image = $photoURL; 
     } 
    } 
?> 

See reference

+0

グレート、ありがとうあなたの時間のためにたくさん! – user1293977

関連する問題