Php 从curl检索信息

Php 从curl检索信息,php,xml,curl,Php,Xml,Curl,我正在使用curl从soundcloud检索信息。它提供了很多信息。但我想过滤它 <?php $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,'http://api.soundcloud.com/tracks '); curl_exec($curl_handle); curl_close($curl_handle); ?> 如何过滤来自它的信息,如流url,可下载的,标

我正在使用curl从soundcloud检索信息。它提供了很多信息。但我想过滤它

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


如何过滤来自它的信息,如
流url
可下载的
标题
等。

有许多工具可用于提取所需内容

您正在下载的流是一个xml文件,因此您可以通过管道将该文件的输出传输到某个解析器,无论是在php中还是直接在命令行上

您可以在此处看到内置的php XML解析器:

编辑下面是一个示例用法

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

?>
track作为$track){
打印“{$track->title}\n”;
打印“\tStream URL:{$track->{'stream-URL'}}}\n”;
}
?>
我最终改用SimpleXML


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

?>

谢谢,这将对我集成api非常有帮助。谢谢,这将对我集成api非常有帮助