13 February 2023

How to get data from XML file in PHP?

Get data from XML file in PHP



$rss_link = "http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml"; //xml_file_link   

// Load xml data.
$xml = file_get_contents($rss_link);
// Strip whitespace between xml tags
$xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml);
// Convert CDATA into xml nodes.
$rss_feed = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA

$rss_feed_channel = $rss_feed->channel;

$rss_feed_channel_item = $rss_feed->channel->item 

                                                         or

$rss_link = "http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml"; //xml_file_link   

//$rss_feed = simplexml_load_file($rss_link, 'SimpleXMLElement', LIBXML_NOCDATA);

   $rss_feed = file_get_contents($rss_link);

   //mb_convert_encoding($rss_feed, 'UTF-16LE', 'UTF-8');

   $rss_feed = new SimpleXmlElement($rss_feed); 

$rss_feed_channel = $rss_feed->channel;

$rss_feed_channel_item = $rss_feed->channel->item 


or

$context = stream_context_create( array( 'http' => array( 'follow_location' => false ) ) ); 

$content = file_get_contents("http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml", false, $context); 

$data = new SimpleXmlElement($content); 

foreach($data->channel->item as $entry) 

    { if ($media = $entry->children('media', TRUE)) 

        { echo "<div style=\"width:160px;display:block;float:left;padding:15px;\">"; 

        $attributes = $media->content->attributes(); 

        $src = $play_attributes['url']; 

            if ($media->thumbnail) 

                    { $attributes = $media->thumbnail->attributes(); 

                    $imgsrc = (string)$attributes['url']; 

                    echo "<img src=\"$imgsrc\" alt=\"\" \/>"; 

                    } 

        } 

$pub_date= explode("-",$entry->pubDate); 

echo date('F d,Y',strtotime(trim($pub_date[0]))); 

echo "</div>"; }

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...