2010-06-24 5 views
1

Je récupère des informations de soundcloud en utilisant curl. ça donne beaucoup d'informations. mais je veux le filtrer.récupération d'informations à partir de curl

<?php 
    $curl_handle=curl_init(); 
    curl_setopt($curl_handle,CURLOPT_URL,'http://api.soundcloud.com/tracks '); 
    curl_exec($curl_handle); 
    curl_close($curl_handle); 
?> 

comment puis-je filtrer les informations provenant comme stream-url, downloadable, title etc.

Répondre

2

Il y a un certain nombre d'outils pour extraire ce que vous voulez. Le flux que vous téléchargez est un fichier xml, vous pouvez donc rediriger la sortie vers un analyseur, soit en php, soit directement sur la ligne de commande.

Vous pouvez voir l'analyseur XML intégré pour php ici: http://php.net/manual/en/book.xml.php

EDIT Voici un exemple d'utilisation

<?php 
// Download the Data 
$curl_handle=curl_init(); 
curl_setopt($curl_handle,CURLOPT_URL,'http://api.soundcloud.com/tracks '); 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,true); 
$xml_data = curl_exec($curl_handle); 
curl_close($curl_handle); 

//Parse it 
$xml = simplexml_load_string($xml_data); 

foreach ($xml->track as $track) { 
    print "{$track->title}\n"; 
    print "\tStream URL: {$track->{'stream-url'}}\n"; 
} 

?> 

je fini par utiliser au lieu SimpleXML

+0

grâce, il sera très aide fule pour moi jusqu'à l'intégration de l'api – rajanikant

0
<?php 

$url = 'http://api.soundcloud.com/tracks'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$body = curl_exec($ch); 
curl_close($ch); 

$parser = xml_parser_create(); 
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); 
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 
xml_parse_into_struct($parser, $body, $data); 
xml_parser_free($parser); 

print "<h1>The XML as a relatively flat PHP data structure</h1>"; 
print "<pre>"; 
print htmlentities($body); 
print "</pre>"; 
print "<hr />"; 
print "<h1>The Raw XML Data</h1>"; 
print "<pre>"; 
print htmlentities(print_r($data, true)); 
print "</pre>"; 
print "<pre>"; 

?> 
+0

merci ça sera très utile fule pour moi jusqu'à intégrer l'api – rajanikant

Questions connexes