What are the best practices for handling browser-specific content in PHP without relying on user agent detection?

When handling browser-specific content in PHP without relying on user agent detection, the best practice is to use feature detection instead. This involves checking if a specific feature is supported by the browser rather than identifying the browser itself. This approach is more reliable and future-proof as it focuses on the capabilities of the browser rather than its user agent string.

<?php
if (function_exists('imagecreatefromjpeg')) {
    // Browser supports JPEG image processing
    // Display JPEG images or perform related actions
} else {
    // Browser does not support JPEG image processing
    // Handle the situation accordingly
}
?>