duanping1920 2013-05-05 23:03
浏览 20
已采纳

从XML获取3个URL,随机选择一个保存到变量

I'm in over my head at this point - but what i have currently looks like this:

<?php
    $request_url = "http://aethereverywhere.tumblr.com/api/read?type=photo&tagged=ae&start=0&num=1";
    $xml = simplexml_load_file($request_url);
    $img = $xml->posts->post->{'photo-url'};
?>

If increase &num to 3, lets say - it'll pull three files, and simplexml_load_file will parse them out - and save them to $img - but what i'd like to is have only one URL saved to $img, selected at random.

Thanks for the help

  • 写回答

3条回答 默认 最新

  • dongluo8303 2013-05-05 23:31
    关注

    New code: select a random image from 0 to 118 (total 119), then outputing, choose the highest resolution.

    <?php
        $request_url = "http://aethereverywhere.tumblr.com/api/read?type=photo&start=".rand(0,118);
        $xml = simplexml_load_file($request_url);
        $img = $xml->posts->post->{'photo-url'};
        $img=(array)$img;
    
        echo '<img src="'.$img[0].'">';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有人会SIRIUS 5.8.0这个软件吗
  • ¥30 comsol仿真等离激元
  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题
  • ¥15 MS中不知道高分子的构型怎么构建模型