How can XML files be used to display videos on a website using PHP?
To display videos on a website using PHP, you can use XML files to store information about the videos such as the title, description, and file path. By parsing the XML file in PHP, you can dynamically generate HTML code to display the videos on the website. This allows for easy management and updating of the video content without directly editing the website code.
<?php
// Load the XML file
$xml = simplexml_load_file('videos.xml');
// Loop through each video in the XML file
foreach($xml->video as $video) {
echo '<div>';
echo '<h2>' . $video->title . '</h2>';
echo '<p>' . $video->description . '</p>';
echo '<video controls>';
echo '<source src="' . $video->file_path . '" type="video/mp4">';
echo 'Your browser does not support the video tag.';
echo '</video>';
echo '</div>';
}
?>