Are there any best practices for playing music in different browsers using PHP?

When playing music in different browsers using PHP, it is important to use HTML5 audio tags to ensure compatibility across various browsers. Additionally, it is recommended to provide multiple audio formats (such as mp3, ogg, and wav) to accommodate different browser capabilities. Using PHP, you can dynamically generate the HTML audio tag with the appropriate source formats based on the user's browser.

<?php
$audioFile = 'example.mp3';
$audioType = 'audio/mpeg';

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false) {
    $audioType = 'audio/mpeg';
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {
    $audioType = 'audio/ogg';
}

echo '<audio controls>';
echo '<source src="' . $audioFile . '" type="' . $audioType . '">';
echo 'Your browser does not support the audio element.';
echo '</audio>';
?>