php code to read rss feed

Solutions on MaxInterview for php code to read rss feed by the best coders in the world

showing results for - "php code to read rss feed"
Octave
23 Nov 2019
1<?php
2$url = "https://www.youtube.com/feeds/videos.xml?channel_id=UCbMi18KmKXRb79716KgnVOA";
3$xml = simplexml_load_file($url) or die("Error: Cannot create object");
4
5//echo "number of entries: " . count($xml->entry) . "<br/>";
6$i = 0;
7while($i <= count($xml->entry)-1){
8    //<id>yt:video:7AQdAE_Yhck</id>
9    echo str_replace("yt:video:", "", $xml->entry[$i]->id[0])  . "<br/><br/>";
10    //<title>Michigan Capitol Building Lansing Michigan</title>
11    echo str_replace("yt:video:", "", $xml->entry[$i]->title[0])  . "<br/><br/>";
12    //<author>
13    //<name>Michigan Constitutional Crusader</name>
14    echo str_replace("yt:video:", "", $xml->entry[$i]->author[0]->name[0])  . "<br/><br/>";
15    //$result = $xml->xpath('*//media:group/media:description');
16    //<yt:videoId>7AQdAE_Yhck</yt:videoId>
17    echo $xml->xpath('*//yt:videoId')[$i]  . "<br/><br/>";
18    //<media:starRating count="20" average="4.60" min="1" max="5"/>
19    echo $xml->xpath('*//media:starRating/@count')[$i] ." ". $xml->xpath('*//media:starRating/@average')[$i]  . "<br/><br/>";
20    //<media:description></media:description>
21    echo $xml->xpath('*//media:description')[$i]  . "<br/><br/>";
22    $i++;   
23}
24
25?>
Greta
24 Jan 2019
1<?php
2 
3function getFeed($feed_url) {
4     
5    $content = file_get_contents($feed_url);
6    $x = new SimpleXmlElement($content);
7     
8    echo "<ul>";
9     
10    foreach($x->channel->item as $entry) {
11        echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
12    }
13    echo "</ul>";
14}
15?>
16