Solved

RSS Feed Enclosure URL

Posted on 2016-09-08
1
63 Views
Last Modified: 2016-09-10
I'm trying to grab just the url from the enclosure tag

<rss version="2.0">
<channel>
<title>
<![CDATA[ Queryfeed | #golf,from:nrileykc ]]>
</title>
<ttl>10</ttl>
<description>
Queryfeed searches in Twitter, Google+ and gives you a nice RSS. Enjoy!
</description>
<generator>queryfeed.net</generator>
<webmaster>admin@queryfeed.net</webmaster>
<item>
<link>
http://twitter.com/twitter/status/773970114764869632
</link>
<guid>
http://twitter.com/twitter/status/773970114764869632
</guid>
<title>
<![CDATA[ Nathan Riley @nrileykc ]]>
</title>
<author>nrileykc</author>
<enclosure url="http://pbs.twimg.com/media/Cr2xto1UkAA56xV.jpg" type="image/jpeg"/>
<category>golf</category>
<pubDate>Thu, 08 Sep 2016 19:43:49 +0000</pubDate>
<description>
<![CDATA[
<a href="https://twitter.com/hashtag/golf">#golf</a> test https://t.co/7SBUt9cd0A
]]>
</description>
</item>
<item>
<link>
http://twitter.com/twitter/status/773954372262699008
</link>
<guid>
http://twitter.com/twitter/status/773954372262699008
</guid>
<title>
<![CDATA[ Nathan Riley @nrileykc ]]>
</title>
<author>nrileykc</author>
<category>golf</category>
<pubDate>Thu, 08 Sep 2016 18:41:16 +0000</pubDate>
<description>
<![CDATA[
test <a href="https://twitter.com/hashtag/golf">#golf</a>
]]>
</description>
</item>
</channel>
</rss>

Open in new window

0
Comment
Question by:N R
1 Comment
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
See if this gets what you want: https://iconoun.com/demo/temp_nr.php
<?php // demo/temp_mr.php
/**
 * https://www.experts-exchange.com/questions/28968617/RSS-Feed-Enclosure-URL.html
 *
 * http://php.net/manual/en/ref.simplexml.php
 * http://php.net/manual/en/class.simplexmlelement.php
 */
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
echo '<pre>';


// TEST DATA FROM THE POST AT E-E
$xml = <<<EOX
<rss version="2.0">
<channel>
<title>
<![CDATA[ Queryfeed | #golf,from:nrileykc ]]>
</title>
<ttl>10</ttl>
<description>
Queryfeed searches in Twitter, Google+ and gives you a nice RSS. Enjoy!
</description>
<generator>queryfeed.net</generator>
<webmaster>admin@queryfeed.net</webmaster>
<item>
<link>
http://twitter.com/twitter/status/773970114764869632
</link>
<guid>
http://twitter.com/twitter/status/773970114764869632
</guid>
<title>
<![CDATA[ Nathan Riley @nrileykc ]]>
</title>
<author>nrileykc</author>
<enclosure url="http://pbs.twimg.com/media/Cr2xto1UkAA56xV.jpg" type="image/jpeg"/>
<category>golf</category>
<pubDate>Thu, 08 Sep 2016 19:43:49 +0000</pubDate>
<description>
<![CDATA[
<a href="https://twitter.com/hashtag/golf">#golf</a> test https://t.co/7SBUt9cd0A
]]>
</description>
</item>
<item>
<link>
http://twitter.com/twitter/status/773954372262699008
</link>
<guid>
http://twitter.com/twitter/status/773954372262699008
</guid>
<title>
<![CDATA[ Nathan Riley @nrileykc ]]>
</title>
<author>nrileykc</author>
<category>golf</category>
<pubDate>Thu, 08 Sep 2016 18:41:16 +0000</pubDate>
<description>
<![CDATA[
test <a href="https://twitter.com/hashtag/golf">#golf</a>
]]>
</description>
</item>
</channel>
</rss>
EOX;


// MAKE AN OBJECT AND FIND THE URL IN THE ENCLOSURE TAG
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$url = (string)$obj->channel->item[0]->enclosure->attributes()->url;
var_dump($url);

Open in new window

Outputs:
string(46) "http://pbs.twimg.com/media/Cr2xto1UkAA56xV.jpg"

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now