Quantcast
Channel: Active questions tagged feed+php+simplexml - Stack Overflow
Viewing all articles
Browse latest Browse all 16

PHP SimpleXML: Feed modification

$
0
0

I want to modify an RSS feed. I want to remove X items from feed and then return the new feed as XML.

<?php
class RSS {
    private $simpleXML;

    public function __construct($address) {
        $xml = file_get_contents($address);
        $this->simpleXML = simplexml_load_string($xml);
    }

    private function getRssInformation() {
        // Here I want to get the Rss Head information ...
    }

    // Here I get X items ...
    private function getItems($itemsNumber, $UTF8) {
        $xml = null;
        $items = $this->simpleXML->xpath('/rss/channel/item');

        if(count($items) > $itemsNumber) {
            $items = array_slice($items, 0, $itemsNumber, true);
        }

        foreach($items as $item) {
            $xml .= $item->asXML() . "\n";
        }

        return $xml;
    }

    public function getFeed($itemsNumber = 5, $UTF8 = true) {
        // Here i will join rss information with X items ...
        echo $this->getItems($itemsNumber, $UTF8);
    }
}
?>

Is it possible with XPath? Thank you.


Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>