Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Come sostituire simple xml?

    Ciao a tutti,

    ho una funzione php per recuperare immagini da flickr che utilizza la funzione simplexml_load_file.

    Ho cambiato hosting e lo script non funziona più perchè è disattivato allow_url_fopen (mi hanno consigliato di usare cURL).

    Avete qualche idea su come modificare il codice per poter recuperare diversamente l'xml?


    codice:
    <?php 
    
    function get_flickr_images( $id, $type = '0',$first, $after, $width, $height ) {
     
     //check if is set the id
     if(!isset($id)) return null;
     
     //check if width & height are sets
     if(!isset($width) || !isset($height) )
     $dim = '';
     else
     $dim = " width='".$width."' height='".$height."' ";
     
     //check if the script gets the album or a set
     ($type > 0) ?
     $url = "http://api.flickr.com/services/feeds/photoset.gne?set=".$type."&nsid=".$id."&lang=it-it&format=atom" :
     $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=".$id."&lang=it-it&format=atom";
     
     //connect to the atom feed
     $xml = simplexml_load_file($url) or die ("Unable to load XML file");
     
     //get the url and the image and save them into an array
     $flickr = Array();
     foreach( $xml->entry as $row ) {
     array_push( $flickr, $first . "[img]" . $row->link[1][[/img]" . $after . "\n" );
     }
     
     //return the array
     return $flickr;
     
    }
    
    ?>

  2. #2
    Utente di HTML.it L'avatar di Razorblade
    Registrato dal
    Feb 2002
    Messaggi
    1,308
    Ciao,
    la soluzione che ti hanno proposto è esatta, devi usare cUrl per recuperare l'xml, quindi parsarlo con SimpleXml.
    Ho postato pochi giorni fa la funzione che ti può essere d'aiuto a risolvere in questa discussione

    Fammi sapere.

    Ciao

  3. #3
    ti ringrazio.

    Ma una cosa di questo tipo?

    codice:
     
     ($type > 0) ?
     $url = "http://api.flickr.com/services/feeds/photoset.gne?set=".$type."&nsid=".$id."&lang=it-it&format=atom" :
     $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=".$id."&lang=it-it&format=atom";
     
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_HEADER, false); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     $data = curl_exec($ch); 
     $error = curl_errno($ch); 
     curl_close($ch); 
     
     $xml = simplexml_load_file($data) or die ("Unable to load XML file");
     
     $flickr = Array();
     foreach( $xml->entry as $row ) {
     array_push( $flickr, $first . "[img]" . $row->link[1][[/img]" . $after . "\n" );
     }

  4. #4
    Ok funziona! grazie mille ;-)

  5. #5
    Utente di HTML.it L'avatar di Razorblade
    Registrato dal
    Feb 2002
    Messaggi
    1,308
    Prego

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.