Php for browser styles

Does anyone know the correct way of serving up css styles for different browsers as external links, particularly ie7, with php?

I think it should work something like this:


<?php
    
    $agent = getenv("HTTP_USER_AGENT");
    
    $style = "<link rel=\"stylesheet\" href=\"resources/style.css\" type=\"text/css\" media=\"projection, screen\" charset=\"utf-8\" />";
    
    if (preg_match("/MSIE 7/i", "$agent")) {
        $style = "<link rel=\"stylesheet\" href=\"resources/ie7.css\" type=\"text/css\" media=\"projection, screen\" charset=\"utf-8\" />";
    }
    
?>

<?php echo $style; ?>

for some reason, this seems to give ie7 the same stylesheet as all the other browsers.

thank you
any help is appreciated.