How can PHP be used to detect different browsers and display specific CSS styles accordingly?

To detect different browsers and display specific CSS styles accordingly in PHP, you can use the $_SERVER['HTTP_USER_AGENT'] variable to get the user's browser information. Based on the user agent string, you can then conditionally include different CSS files or add specific styles inline.

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'Firefox') !== false) {
    echo '<link rel="stylesheet" type="text/css" href="firefox-styles.css">';
} elseif (strpos($user_agent, 'Chrome') !== false) {
    echo '<link rel="stylesheet" type="text/css" href="chrome-styles.css">';
} else {
    echo '<link rel="stylesheet" type="text/css" href="default-styles.css">';
}