【问题标题】:Choosing the photo size in tumblr API在 tumblr API 中选择照片尺寸
【发布时间】:2012-03-27 15:58:54
【问题描述】:

我想在我的网站中包含来自 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>

现在如何在此处的第三行指定我想要 250 版本?

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

谢谢!

【问题讨论】:

    标签: php xml api tumblr


    【解决方案1】:

    你必须遍历它们来选择你想要的。

    <?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

    【讨论】:

      猜你喜欢
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 2011-08-31
      • 2012-10-20
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多