Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在tumblr API中选择照片大小_Php_Xml_Api_Tumblr - Fatal编程技术网

Php 在tumblr API中选择照片大小

Php 在tumblr API中选择照片大小,php,xml,api,tumblr,Php,Xml,Api,Tumblr,我想把tumblr博客上的最新帖子放在我的网站上,效果很好。不过,我不知道如何从API中选择特定的标记 XML具有以下结构: <tumblr> <posts> <post> <photo-url max-width="500"> image_500.jpg </photo-url> <photo-url

我想把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>

image_500.jpg
image_250.jpg
现在,我如何在第三行中指定我想要的250版本

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

谢谢大家!

您必须在它们之间循环以选择您想要的一个

<?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;
        }
    }
?>
posts->post->{'photo-url'}作为$photoURL){
如果((字符串)$photoURL['max-width']=='250'){
$image=$photoURL;
}
}
?>