Search code examples
phpcssinternet-explorer-9

( i.e stylesheets) for different languages?


<?php if($_COOKIE['lang'] != 'en') echo '<link rel="stylesheet" href="css/'.$_COOKIE['lang'].'.css"/>'; ?>

With this above script you get the stylesheet for the language that is selected. Like if you select France you get the stylesheet fr.css

But now I want the same for IE so I thought something like this.

<?php if($_COOKIE['lang'] != 'en') echo '<link rel="stylesheet" href="css/'.$_COOKIE['lang'].'ie.css"/>'; ?>

So now when you click on France it also opens frie.css But what do I write in here to make it only for IE

<!--[if IE]><style>@import url('/css/ie.css');</style><![endif]-->

Thanks!


Solution

  • <?php 
     if($_COOKIE['lang'] != 'en'){ 
        printf('<!--[if IE]><style>@import url(\'/css/%sie.css\');</style><![endif]-->', $_COOKIE['lang']); 
     }
    ?>
    

    This is what you need to write. You can also check in PHP headers if browser is Internet Explorer.

    You can use $_SERVER['HTTP_USER_AGENT'] or get_browser() function to check it in PHP.