php - Get 3 URLs from XML, randomly select one to save to variable -


i'm in on head @ point - have looks 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 3, lets - it'll pull 3 files, , simplexml_load_file parse them out - , save them $img - i'd have 1 url saved $img, selected @ random.

thanks help

new code: select random image 0 118 (total 119), outputing, choose 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].'">'; ?> 

Comments