[英]php curl to get xml feed does not return all the data
So I have this private function: 所以我有这个私有功能:
private function curl_get($url)
{
// Initiate the curl session
$ch = curl_init();
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
// Removes the headers from the output
curl_setopt($ch, CURLOPT_HEADER, 0);
// Return the output instead of displaying it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Execute the curl session
$output = curl_exec($ch);
// Close the curl session
curl_close($ch);
return $output;
}
And I use if for example with this link: http://www.metacafe.com/api/item/cb-xuFyGC0jJqPfhMoFnewj4Da_ZhHCz4L2/ 例如,我使用以下链接: http : //www.metacafe.com/api/item/cb-xuFyGC0jJqPfhMoFnewj4Da_ZhHCz4L2/
now the problem is that doesn't return all the data, all I get is this: 现在的问题是不会返回所有数据,我得到的是:
[data] => SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
[source] => Metacafe
)
[title] => Metacafe
[channel] => SimpleXMLElement Object
(
[title] => SimpleXMLElement Object
(
)
[link] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/
[image] => SimpleXMLElement Object
(
[url] => http://s.mcstatic.com/Images/MCLogo4RSS.jpg
[link] => http://www.metacafe.com
[title] => Metacafe
[height] => 65
[width] => 229
)
[description] => SimpleXMLElement Object
(
)
[item] => SimpleXMLElement Object
(
[id] => cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ
[author] => CBS
[title] => Romney Concedes South Carolina Primary
[link] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/romney_concedes_south_carolina_primary/
[rank] => 4.00
[category] => News & Events
[description] => SimpleXMLElement Object
(
)
[guid] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/romney_concedes_south_carolina_primary/
[pubDate] => 18 hours ago +0000
)
)
)
Why isn't it returning the description and the tags, which are pretty important to me? 为什么不返回对我来说很重要的描述和标签?
It's not due to curl
but how SimpleXml handles CDATA: 这不是由于
curl
造成的,而是SimpleXml处理CDATA的方式:
$xml = simplexml_load_string($stringFromCurl, 'SimpleXMLElement', LIBXML_NOCDATA);
will interpret the CDATA as text nodes, see the XML constants on PNP.net 将CDATA解释为文本节点,请参见PNP.net上的XML常量
SimpleXML确实具有“所有数据”,只是通过print_r()
不可见。
echo $your_simplexml_object->channel->item->description;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.