我有这个XML文件:
http://www.dailymotion.com/rss/tag/house
我需要获得第一个标题和描述项目的内容。比我使用这段代码:
$xml = simplexml_load_file('http://www.dailymotion.com/rss/tag/house/', 'SimpleXMLElement', LIBXML_NOCDATA);
$dom = new DOMDocument();
echo $xml->channel->item->title . "<br>";
@$dom->loadHtml($xml->channel->item->description);
$xpath = new DOMXPath($dom);
echo $description = $xpath->evaluate("string(//p[1]/text())");
这是OUTPUT
Fabio Lenzi - Beautiful Sorrow (Ivan Scratchin Funky Mix)
Download:
但如果我读了xml,在描述项中我会在p tag中找到这个内容:
<p>Download:<br>https://itunes.apple.com/it/album/beautiful-sorrow/id661901853<br><br>©
Copyright protected work. ℗ Frutilla Records - All rights reserved. Only for watching,
listening and streaming. Downloading, copying, sharing and making available is strictly
prohibited.<br>
<br>frutillarecords@gmail.com<br>alex.voghi@dancetool.net<br>info@dancetool.net -
YourDancefloorTV – (Re)Discover your Dance greatest hits - YourDancefloorTV is your
channel for all the best Dance music. Find your favorite tracks and artists and
experience the best of Dance music. Subscribe for free to stay connected to our channel
and easily access our video updates! - YourDancefloorTV:
http://www.dailymotion.com/yourdancefloortv</p>
比我注意到解析从&lt; br&gt;标签。如何忽略br标签和其他段落中包含的任何标签? 任何帮助它真的很感激。
答案 0 :(得分:1)
使用strip_tags
删除html代码!
示例:
$stripped_string = strip_tags($unstripped_string, $allowable_tags);
答案 1 :(得分:0)
这可能是,
$x = // Your Result;
echo strip_tags($x,'<p>');