php - RSS Feed fetch as a JSON object -
this php file named testclient
**public function getxml() { $xml = simplexml_load_file('https:/.............'); $feed1 = '<h3>' . $xml->channel->title . '</h3>'; foreach ($xml->channel->item $item) { $feed1 .= '<h4><a href="' . $item->link . '">' . $item->title . "</a></h4>"; } $xml = simplexml_load_file('https://rumble.com/rss.php?target=sprinklevideo'); $feed2 = '<h3>' . $xml->channel->description . '</h3>'; foreach ($xml->channel->item $item) { $feed2 .= '<h4><a href="' . $item->link . '">' . $item->description . "</a></h4>"; } $xml = simplexml_load_file('https://rumble.com/rss.php?target=sprinklevideo'); $feed3 = '<h3>' . $xml->channel->link . '</h3>'; foreach ($xml->channel->item $item) { $feed3 .= '<h4><a href="' . $item->link . '">' . $item->link . "</a></h4>"; } return $feed1; }**
this controller class want viewing result
** use videobundle\videoproviderclient\testclient testclient; class maincontroller extends controller { public function mainaction() { $zoo = new testclient(); $val = $zoo->getxml(); //dump echo "<pre>"; var_dump($val); echo "</pre>"; die(); return new response("$val"); } public function setval($val) { $this->item = json_encode($val); return $this; } public function getval() { if ($this->item) { return json_decode($val); } return null; }
**
if want fetch data rss feed title/description/link, getting those. how can data json object. because in rss feed data saving item.
this sample "item" data rss feed ---
**
<item> <title>newlyweds stun guests epic first dance</title> <description> foot in time music! </description> <link> https://zzx.com/v2zl27-bride-and-groom-perform-the-best-first-dance-ever-to-a-swingin-classic.html </link> <guid ispermalink="false">media/8.5087</guid> <pubdate>2015-06-03 12:49:16</pubdate> <media:category scheme="http://search.yahoo.com/mrss/category_schema">viral</media:category> <media:keywords> viral videos, inspiring first wedding dance, songs first wedding dance </media:keywords> <media:thumbnail url="https://rumble.com/rss/8-5019487.jpg" /> <media:player url="https://asdas.com/bin/8_8" height="426" width="491" /> <media:content url="https://i.rmbl.ws/s8/d99" type="video/mp4" /> </item>
**
thanks in advance ...
you adding html data on first step. should @ end. , best option twig template.
then parsing xml json quite simple:
$xml = simplexml_load_string($xmlstring); $json = json_encode($xml);
Comments
Post a Comment