我使用https://github.com/willvincent/feeds来读取rss,对于所有字段,我还需要获取pubDate字段。 我没有找到用于它的方法(我也在源程序app / library / AppRssImport.php文件中进行了查找),并且进行了一些调试,因此方法
echo json_encode(true);
具有下一个输出:
$.ajax({
url: 'scripts/AjaxHandler/Controller.php',
type: 'POST',
dataType: 'JSON',
data: {
action: 'doThis',
var1: var1,
var2: var2
},
success: function (data) {
if(data == true) {
alert('success');
}else{
alert('failure');
}
},
error: function (error) {
console.log(error);
}
});
和https://imgur.com/a/wTmd9cV 我试图读取pubDate字段的值,但失败了。这种结构对我来说很奇怪。 哪个是正确的决定?
答案 0 :(得分:0)
您可以使用get_date()
方法来获取pubDate
的值吗?
https://github.com/willvincent/feeds此插件只是SimplePie php扩展的包装。您可以查看SimplePie文档以获取所有其他可用方法。 http://simplepie.org/api/class-SimplePie_Item.html。
可用的代码可能像这样。我使用了laravel,因此抓取Feed的第一行可能有所不同。
$feed = Feeds::make('https://www.example.com/feed/');
$items = $feed->get_items();
foreach( $items as $key => $item ) {
$title = $item->get_title();
$guid = $item->get_id();
$pub_date = $item->get_date();
}