tags:

views:

55

answers:

2

hi ! i am retriving information from soundcloud using curl.it gives lot of information .but i want to filter it .

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

how can i filter information coming from it like stream-url, downloadable, title etc.

+1  A: 

There are a number of tools for extracting what you want.

The stream you're downloading is an xml file, so you can pipe the output of that to some parser, either in php or directly on the commandline.

You can see the builtin XML parser for php here: http://php.net/manual/en/book.xml.php

EDIT Here's an example usage

<?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";
}

?>

I ended up using SimpleXML instead

Jamie Wong
thanks it will be very help fule for me up to integrating api
rajanikant
A: 
<?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>";

?>
artlung
thanks it will be very help fule for me up to integrating api
rajanikant