qrss
1.0.0
一個 API 類,用於將 RSS feed 解析為帶有快取選項的 json。
取得qrss
類別並在您的 php 檔案中使用 require 它。
require ' src/qrss.php ' ;
// To fetch an RSS feed as json use
( new qrss ( ' https://news.google.com/?output=rss ' ))-> json ();
// For fresh copy you can use fresh() which will ignore cache
( new qrss ( ' https://news.google.com/?output=rss ' ))-> fresh ()-> json ()
// Get the feed ignoring validation adding novalidate()
( new qrss ( ' https://en.blog.wordpress.com/feed/ ' ))-> novalidate ()-> json ();
// There is also an option to get data in plain text using text() instead of json()
( new qrss ( ' https://news.google.com/?output=rss ' ))-> text ();
您也可以擴充 parse 方法來自訂輸出。
class Myqrss extends qrss {
protected function parse ( $ xml )
{
// you have all the xml elements as SimpleXMLElement object
// parse it however you want, return the array from this
return [
' title ' => ( string ) $ xml -> channel -> title
];
}
}
( new My qrss ( ' https://news.google.com/?output=rss ' ))-> json ();