How can PHP be used to fetch and parse XML data from a URL, such as a YouTube feed?

To fetch and parse XML data from a URL, such as a YouTube feed, you can use PHP's built-in functions like file_get_contents to retrieve the XML content and simplexml_load_string to parse it into an object that you can work with. By using these functions, you can easily access and extract the data you need from the XML feed.

$url = 'https://www.youtube.com/feeds/videos.xml?channel_id=YOUR_CHANNEL_ID';
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);

foreach($feed->entry as $entry) {
    $title = $entry->title;
    $link = $entry->link['href'];
    
    echo "Title: $title <br>";
    echo "Link: $link <br><br>";
}