SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: help using REST

  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile help using REST

    How can I display the photos from a web resource below;

    I have no idea where to start;

    http://www.panoramio.com/map/get_pan...38&size=medium


    I can walk through an array, but how do I get the array.

    And help appreciated muchly.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use json_decode().

    PHP Code:
    $str file_get_contents('http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=20&minx=-1&miny=37&maxx=0&maxy=38&size=medium');
    $myarray json_decode($str);
    print_r($myarray); 

  3. #3
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That seems to throw up an error. Although it has pointed me in the right direction

    http://www.spanishpropertymagazine.com/panoramio.php

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your server doesn't support file_get_contents. You might try using curl, but that may be disabled too.

  5. #5
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My web host enabled file get contents, but I can't seem do a while loop through it

    PHP Code:
    <?

    $str 
    file_get_contents('http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=20&minx=-1&miny=37&maxx=0&maxy=38&size=medium');

    $myarray json_decode($str);

    while (
    $myarray) {

        
    $photo_id         =     $myarray['photo_id'];
        
    $photo_title         =     $myarray ['photo_title'];
        
    $photo_url         =     $myarray['photo_url'];
        
    $photo_url_file    =     $myarray['photo_url_file'];
        
    $longitude        =        $myarray['longitude'];
        
    $latitude            =        $myarray['latitude'];
        
    $width                =        $myarray['width'];
        
    $height            =        $myarray['height'];
        
    $upload_date        =        $myarray['upload_date'];
        
        echo 
    "<img src=\"$photo_url_file\"><hr>";
    }

    ?>

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see foreach() and for() loops.

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Those 'arrays' are actually objects, you can access them like so...
    PHP Code:
    <?php
    $oPanoramio 
    json_decode(file_get_contents('http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=20&minx=-1&miny=37&maxx=0&maxy=38&size=medium'));
    foreach(
    $oPanoramio->photos as $oPhoto)
    {
        
    printf(
            
    '<h4>%s</h4>
            <img src="%s" title="%s" alt="%s" />
            <p>Image taken by <a href="%s" target="_blank">%s<a/> on %s</p>'
    ,
            
    $oPhoto->photo_title,
            
    $oPhoto->photo_file_url,
            
    $oPhoto->photo_title,
            
    $oPhoto->photo_title,
            
    $oPhoto->owner_url,
            
    $oPhoto->owner_name,
            
    $oPhoto->upload_date
        
    );
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like I am now using OO programing, at least a bit.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •