0

Here is my code.

$xml = simplexml_load_file("http://www.metacafe.com/api/item/8373557/", NULL, LIBXML_NOCDATA);
$thumbnail = $xml->xpath( "/rss/channel/item/media:thumbnail/@url" );
$duration = $xml->xpath( "/rss/channel/item/media:content/@duration" );
$title = $xml->xpath ( "/rss/channel/item/title");
$desc = $xml->xpath ( "/rss/channel/item/description/");

Here is the XML file content:

<?xml version="1.0" encoding="utf-8"?>
        <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" source="Metacafe">
            <title>Metacafe</title>
            <channel>
                    <title></title>
                    <link>http://www.metacafe.com/watch/8373557/</link>
                    <image>
                        <url>http://s.mcstatic.com/Images/MCLogo4RSS.jpg</url>
                        <link>http://www.metacafe.com</link>
                        <title>Metacafe</title>
                        <height>65</height>
                        <width>229</width>
                    </image>
                    <description></description>
                    <item>
            <id>8373557</id>
            <author>Revision3</author>
            <title>Make Your Photos Look Pro with Pix: Pixel Mixer for IOS and Android - Snapp</title>
            <link>http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/</link>
                    <rank>3.70</rank>
            <category>Science &amp; Tech</category>
            <description>
            <![CDATA[
                    <a href="http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/"><img src="http://s6.mcstatic.com/thumb/8373557/22302729/4/directors_cut/0/1/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp.jpg?v=3" align="right" border="0" alt="Make Your Photos Look Pro with Pix: Pixel Mixer for IOS and Android - Snapp" vspace="4" hspace="4" width="134" height="78" /></a>
                    <p>
                    Create your own professional quality images with this free app from developer colonO.  Pix: Pixel Mixer is simple, beautiful, free and available on both iOS and Android.                   <br>Ranked <strong>3.70</strong> / 5 | 4971 views | <a href="http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/">0 comments</a><br/>
                    </p>
                    <p>
                        <a href="http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/"><strong>Click here to watch the video</strong></a> (01:02)<br/>
                        Submitted By:                       <a href="http://www.metacafe.com/channels/Revision3/">Revision3</a><br/>
                        Tags:
                        <a href="http://www.metacafe.com/topics/pictures/">Pictures</a>&nbsp;<a href="http://www.metacafe.com/topics/pixel_mixer/">Pixel Mixer</a>&nbsp;<a href="http://www.metacafe.com/topics/photo_filters/">Photo Filters</a>&nbsp;<a href="http://www.metacafe.com/topics/filters_for/">Filters For</a>&nbsp;<a href="http://www.metacafe.com/topics/ios_and/">Ios And</a>&nbsp;<a href="http://www.metacafe.com/topics/android/">Android</a>&nbsp;<a href="http://www.metacafe.com/topics/ios_review/">Ios Review</a>&nbsp;<a href="http://www.metacafe.com/topics/instagram_filters/">Instagram Filters</a>&nbsp;                        <br/>
                        Categories: <a href='http://www.metacafe.com/videos/science_and_tech/'>Science &amp; Tech</a>                   </p>
                ]]>
            </description>
                        <guid isPermaLink="true">http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/</guid>
            <pubDate>16-Apr-12 +0000</pubDate>
                        <media:player url="http://www.metacafe.com/watch/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp/" />
                        <media:content url="http://www.metacafe.com/fplayer/8373557/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp.swf" type="application/x-shockwave-flash" medium="video" height="360" width="640" duration="62" />             <media:thumbnail url="http://s6.mcstatic.com/thumb/8373557/22302729/4/catalog_item5/0/1/make_your_photos_look_pro_with_pix_pixel_mixer_for_ios_and_android_snapp.jpg?v=3" />
            <media:title>Make Your Photos Look Pro with Pix: Pixel Mixer for IOS and Android - Snapp</media:title>
            <media:keywords>Pictures,Pixel Mixer,Photo Filters,Filters For,Ios And,Android,Ios Review,Instagram Filters</media:keywords>
                        <media:description>Create your own professional quality images with this free app from developer colonO.  Pix: Pixel Mixer is simple, beautiful, free and available on both iOS and Android.</media:description>
                        <media:credit>Revision3</media:credit>
                            <media:rating scheme="urn:simple">nonadult</media:rating>
                </item>
            </channel></rss>

I want to extract the Tags content and do not know which expression should I do to print that? I successfully get thumbnail, duration, title, but failed to get tags inside CDATA / inside description.

Any help?

1 Answer 1

2

In a first step you need to fetch the content of the <description> tag by using $xml->rss->channel->item->description, or with an xpath expression like the ones you have. Then you use a regex on this content to fetch the links with the tag name. The regex should be something like this:

~<a href="http://www.metacafe.com/topics/(?P<foobar>[^"]+)/">(?P<tag>[^<]+)</a>~

Another way would be to ask for an API which you can use to get the tags from an entry.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.