FuelPHP1.2のお話。
最近FuelPHPをよく弄っているんだけど、色々なデータをパースする事ができるFormat::forgeでRSSをパースしたところ、RSS1.0の「dc:date」を取得する事ができなかった。
$feed_string = file_get_contents('http://rss.url.com/'); $data = Format::forge($feed_string,'XML');
fuel/core/classes/format.phpの_from_xmlメソッドを確認してみたが、その部分を補完する記述なし。仕方ないので自作で対応。
$xml= new SimpleXMLElement($feed_string); foreach($xml->item as $row){ $tmp = array(); $tmp['title'] = (string)$row->title; $tmp['link'] = (string)$row->link; $tmp['description'] = strip_tags((string)$row->description); $dc = $row->children('http://purl.org/dc/elements/1.1/'); $tmp['date'] = date('Y.m.d H:i:s', strtotime($dc->date)); $tmp['time_stamp'] = (int)strtotime($dc->date); $data[] = $tmp; }
まあRSSはしょうがないのかな。