开发者

How to use Last.fm XML-RPC response with CodeIgniter?

开发者 https://www.devze.com 2023-02-09 15:16 出处:网络
A few days ago I had posted a questions about how to Request user recenttracks from lastfm with codeigniter and xmlrpc

A few days ago I had posted a questions about how to Request user recenttracks from lastfm with codeigniter and xmlrpc The request works fine, but still i can't figure out how to use the response...This is what I have done so far:

My Problem with xml-rpc is that the response that I get is a string...

if(!$this->xmlrpc->send_request())
{
    $data["response"] = $this->xmlrpc->display_error();
}
else {
    $data["response"] = $this->xmlrpc->display_response();
}

var_dump says $data["response"] is a string(4293)...

I tried var_dump(simplexml_load_string($response)); but I get an error:

Message: simplexml_load_str开发者_如何学编程ing() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found

So how am I supposed to use this response?

xml-rpc is sooo bad documented in the CodeIgniter UserGuide... :(


If you look at the actual response returned from Last.fm via CodeIgniter's XML-RPC class, it looks like this:

&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;
<lfm status=\"ok\">
<recenttracks user=\"RJ\" page=\"1\" perPage=\"10\" totalPages=\"3327\" total=\"33265\" >
<!-- truncated for brevity -->

I'm hoping maybe someone can provide a better answer as this doesn't feel like an optimal solution to me but it seems to work:

$response = html_entity_decode(stripslashes($response));

$xml = simplexml_load_string($response);

var_dump($xml);

The var_dump should then look something like this:

object(SimpleXMLElement)#20 (2) { ... }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号