Web::rss PHP Method

rss() public method

Retrieve RSS feed and return as an array
public rss ( $url, $max = 10, $tags = NULL ) : array | FALSE
$url string
$max int
$tags string
return array | FALSE
    function rss($url, $max = 10, $tags = NULL)
    {
        if (!($data = $this->request($url))) {
            return FALSE;
        }
        // Suppress errors caused by invalid XML structures
        libxml_use_internal_errors(TRUE);
        $xml = simplexml_load_string($data['body'], NULL, LIBXML_NOBLANKS | LIBXML_NOERROR);
        if (!is_object($xml)) {
            return FALSE;
        }
        $out = [];
        if (isset($xml->channel)) {
            $out['source'] = (string) $xml->channel->title;
            $max = min($max, count($xml->channel->item));
            for ($i = 0; $i < $max; $i++) {
                $item = $xml->channel->item[$i];
                $list = ['' => NULL] + $item->getnamespaces(TRUE);
                $fields = [];
                foreach ($list as $ns => $uri) {
                    foreach ($item->children($uri) as $key => $val) {
                        $fields[$ns . ($ns ? ':' : '') . $key] = (string) $val;
                    }
                }
                $out['feed'][] = $fields;
            }
        } else {
            return FALSE;
        }
        Base::instance()->scrub($out, $tags);
        return $out;
    }