Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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标记的字符串_Php_Xml_String_Rss - Fatal编程技术网

PHP获取并修改特定RSS标记的字符串

PHP获取并修改特定RSS标记的字符串,php,xml,string,rss,Php,Xml,String,Rss,我有一个游戏的RSS提要。从每个项目中提取、修改和回显选定标记的文本的最佳方法是什么 例如,我想要的文本输出是: Game: Rapunzel Split Up With Flynn (HTML5) Category: girl Image: http://www.website.com/thumb/201611/Rapunzel-Split-Up-With-Flynn.jpg Game: Barbie Clean Place (HTML5) Category: girl Image: http

我有一个游戏的RSS提要。从每个项目中提取、修改和回显选定标记的文本的最佳方法是什么

例如,我想要的文本输出是:

Game: Rapunzel Split Up With Flynn (HTML5)
Category: girl
Image: http://www.website.com/thumb/201611/Rapunzel-Split-Up-With-Flynn.jpg
Game: Barbie Clean Place (HTML5)
Category: girl
Image: http://www.website.com/thumb/201611/Barbie-Clean-Place.jpg
然而,还有更多的项目,正如我刚才展示的许多项目中的两个

<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Game Feed</title> 
<link>http://www.website.com</link>
<description>Game Feed</description>
<language>en-us</language>
<atom:link href="http://website.com" rel="self" type="application/rss+xml" />
<item>
<id>18859</id>
<name>Rapunzel Split Up With Flynn</name>
<type>html5</type>
<description>Rapunzel wants to split up with Flynn, but what the result will be, it depends on you. Can you help her find her true love during this hard period?</description>
<control>Tap on screen on mobile phone and mouse click on PC.</control>
<tags>Princess, Movie, Love, HTML5, Hidden, Girl, Disney, Cartoon, Android</tags>
<category>girl</category>
<thumb>http://www.website.com/thumb/201611/Rapunzel-Split-Up-With-Flynn.jpg</thumb>
<filetype>iframe</filetype>
<file>http://website.com/Rapunzel-Split-Up-With-Flynn/index.php?pubid=website</file>
<width>800</width>
<height>504</height>
<size>8454545</size>
<ad>1</ad>
<copyright>1</copyright>
<resize>1</resize>
<wmode_direct>0</wmode_direct>
<mobile>1</mobile>
<m_width>800</m_width>
<m_height>504</m_height>
<site>website.com</site>
<publishDate>2016-11-15</publishDate>
</item>
<item>
<id>18858</id>
<name>Barbie Clean Place</name>
<type>html5</type>
<description>Little Barbie moved to a new home, following her dad's work transfer. As a new friend, would you like to help her and build a new home for her? Very simple, clean the messy room, and then decorate it, come and try it!</description>
<control>Tap and drag to play on mobile phone and mouse click to play on PC.</control>
<tags>Room, Princess, HTML5, Girl, Educational, Design, Decorate, Cleaning, Cartoon, Barbie, Android</tags>
<category>girl</category>
<thumb>http://www.website.com/thumb/201611/Barbie-Clean-Place.jpg</thumb>
<filetype>iframe</filetype>
<file>http://website.com/Barbie-Clean-Place/index.php?pubid=website</file>
<width>800</width>
<height>504</height>
<size>4130080</size>
<ad>1</ad>
<copyright>1</copyright>
<resize>1</resize>
<wmode_direct>0</wmode_direct>
<mobile>1</mobile>
<m_width>800</m_width>
<m_height>504</m_height>
<site>website.com</site>
<publishDate>2016-11-15</publishDate>
</item>
</channel>
</rss>

游戏馈送
http://www.website.com
游戏馈送
美国英语
18859
莴苣姑娘和弗林分手了
html5
莴苣姑娘想和弗林分手,但结果如何取决于你。在这段艰难时期,你能帮她找到真爱吗?
轻触手机屏幕,鼠标点击PC。
公主,电影,爱情,HTML5,隐藏,女孩,迪斯尼,卡通,安卓
女孩
http://www.website.com/thumb/201611/Rapunzel-Split-Up-With-Flynn.jpg
iframe
http://website.com/Rapunzel-Split-Up-With-Flynn/index.php?pubid=website
800
504
8454545
1.
1.
1.
0
1.
800
504
网站
2016-11-15
18858
芭比清洁场所
html5
小芭比随着父亲的工作调动搬到了一个新家。作为一个新朋友,你愿意帮助她并为她建造一个新家吗?很简单,打扫一下凌乱的房间,然后装饰一下,来试试吧!
点击并拖动可在手机上播放,单击鼠标可在PC上播放。
房间、公主、HTML5、女孩、教育、设计、装饰、清洁、卡通、芭比、安卓
女孩
http://www.website.com/thumb/201611/Barbie-Clean-Place.jpg
iframe
http://website.com/Barbie-Clean-Place/index.php?pubid=website
800
504
4130080
1.
1.
1.
0
1.
800
504
网站
2016-11-15

有没有什么好的RSS或XML处理库可以使用,或者一些简单的代码?

用你的XML做json或数组,这样你可以更容易地访问它

$xml = '<xmlstuff></xmlstuff'; // Be warned of ' xml could cause error

$json = json_encode(simplexml_load_string($xml), true);
$arrays = json_decode($json, true);

echo "<pre>";
var_dump($arrays);
echo "</pre>";

$xml=”我用于RSS提要,效果非常好。现在我接受了一点离题的答案,但您知道如何在不转换为json的情况下对项运行foreach循环,所以常规的简单xml方法是什么?这将是很好的匹配,它的概念与ass数组相同,但更基于对象,因此您可以使用->而不是$xml=simplexml\u load\u string($note);echo$xml->getName()。“
”;foreach($xml->children()as$child){echo$child->getName()。“:“$child.”
“;}谢谢这很有用,我尝试echo$xml->item。“
”;和foreach($xml->item->children()作为$child){但是我得到一个错误:警告:main():节点不再存在。echo$xml->rss->channel->item->name似乎也不起作用。
echo $name1 = $arrays['channel']['item'][0]['name']."<br>";
echo $name2 = $arrays['channel']['item'][1]['name']."<br><br>";

//MORE ADVANCED

foreach ($arrays['channel']['item'] as $items){
    echo $items['name']."<br>";
}