Quantcast
Channel: Creating a simple RSS from dynamic content in PHP - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Creating a simple RSS from dynamic content in PHP

$
0
0

I am creating a simple RSS with dynamic content in PHP and I am using following code:

PHP Code:

$doc = new DOMDocument('1.0');$doc->formatOutput = true;$root = $doc->createElement('rss');$root = $doc->appendChild($root);$xml = simplexml_load_string($xml_data->asXML());foreach($xml->data->item as $item){    $title = $doc->createElement('title');    $title = $root->appendChild($title);    $text = $doc->createTextNode($item->title);    $text = $title->appendChild($text);    $link = $doc->createElement('link');    $link = $root->appendChild($link);    $text = $doc->createTextNode("http://example.com/xyz/?zyx=".$item->id);    $text = $link->appendChild($text);}echo 'Wrote: ' . $doc->save("/directory/jobs00.xml") . ' bytes';

What result I am getting with above code:

<rss><title>title1</title><link>http://example.com/xyz/?zyx=11008</link><title>title2</title><link>http:/example.com/xyz/?zyx=11009</link></rss>

What result I want:

<rss><channel><item><title>title1</title><link>http://example.com/xyz/?zyx=11008</link></item><item><title>title2</title><link>http://example.com/xyz/?zyx=11009</link></item></channel></rss>

So what i need to modify in my code in order to achieve what i want above.


Viewing all articles
Browse latest Browse all 2

Trending Articles





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