Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php RSS提要作为JSON对象获取_Php_Json_Symfony_Rss - Fatal编程技术网

Php RSS提要作为JSON对象获取

Php RSS提要作为JSON对象获取,php,json,symfony,rss,Php,Json,Symfony,Rss,这是我的PHP文件,名为testClient **public function getXML() { $xml = simplexml_load_file('https:/.............'); $feed1 = '<h3>' . $xml->channel->title . '</h3>'; foreach ($xml->channel->item as $item) {

这是我的PHP文件,名为testClient

  **public function getXML() {

        $xml = simplexml_load_file('https:/.............');
        $feed1 = '<h3>' . $xml->channel->title . '</h3>';
        foreach ($xml->channel->item as $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 as $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 as $item) {
            $feed3 .= '<h4><a href="' . $item->link . '">' . $item->link . "</a></h4>";
        } 
        return $feed1;
}**
**公共函数getXML(){
$xml=simplexml_加载_文件('https://……);
$feed1='.$xml->channel->title';
foreach($xml->channel->item as$item){
$feed1.='”;
}
$xml=simplexml\u加载\u文件('https://rumble.com/rss.php?target=sprinklevideo');
$feed2='.$xml->channel->description';
foreach($xml->channel->item as$item){
$feed2.='”;
}
$xml=simplexml\u加载\u文件('https://rumble.com/rss.php?target=sprinklevideo');
$feed3='.$xml->channel->link';
foreach($xml->channel->item as$item){
$feed3.='”;
} 
返回$feed1;
}**
这是我想要查看结果的控制器类

**

use VideoBundle\VideoProviderClient\testClient as 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;
    }
**
使用VideoBundle\VideoProviderClient\testClient作为测试客户端;
类MainController扩展控制器
{
公共职能部门主要行动(){
$zoo=newtestclient();
$val=$zoo->getXML();
//倾倒
回声“;
<item>
<title>Newlyweds stun guests with epic first dance</title>
<description>
your foot in time to the 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 for 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>
var_dump($val); 回声“;
<item>
<title>Newlyweds stun guests with epic first dance</title>
<description>
your foot in time to the 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 for 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>
模具(); 返回新的响应(“$val”); } 公共函数setVal($val){ $this->item=json_encode($val); 退还$this; } 公共函数getVal(){ 如果($this->item){ 返回json_解码($val); } 返回null; }
**

如果我想从RSS提要中获取数据,比如title/description/link,我正在获取这些数据。但是我如何才能将所有这些数据作为JSON对象获取。因为在RSS提要中,数据保存为项目

这是来自RSS提要的“项”数据示例---

**


新婚夫妇以史诗般的第一支舞惊艳宾客
让你的脚随着音乐走!
https://zzx.com/v2zl27-bride-and-groom-perform-the-best-first-dance-ever-to-a-swingin-classic.html
媒体/8.5087
2015-06-03 12:49:16
病毒的
病毒式视频、鼓舞人心的第一支婚礼舞蹈、第一支婚礼舞蹈歌曲
**


提前感谢…

您在第一步将HTML添加到数据中。您应该在最后添加。最好的选择是使用细枝模板

然后将XML解析为JSON非常简单:


在第一步中,您正在向数据中添加HTML。您应该在最后添加HTML。最好的选择是使用细枝模板

然后将XML解析为JSON非常简单: