IE conditional statements in php docs

  • theBruney
  • Student
  • Student
  • User avatar
  • Posts: 67
  • Loc: China

Post 3+ Months Ago

Hello there,

I tried using these two statements:

Code: [ Select ]
<!--[if lt IE 7]><link rel="stylesheet" href="<?php echo $mosConfig_live_site;?>/styles/IEStyle.css" type="text/css" /><![endif]--> and also
<!--[if IE]><link rel="stylesheet" href="<?php echo $mosConfig_live_site;?>/IEStyle.css" type="text/css" /><![endif]-->
  1. <!--[if lt IE 7]><link rel="stylesheet" href="<?php echo $mosConfig_live_site;?>/styles/IEStyle.css" type="text/css" /><![endif]--> and also
  2. <!--[if IE]><link rel="stylesheet" href="<?php echo $mosConfig_live_site;?>/IEStyle.css" type="text/css" /><![endif]-->


to target the IE 6 browser in a .php file. I placed the comment between the <head> tags of the .php document. Can anyone spot errors on the code syntax? Seems like the .php file isn't reading the conditional statement, only the straight off
Code: [ Select ]
<link rel="stylesheet" />
tag.


Thanks.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

eh, why not just use all PHP? Less code goes to the browser and makes for faster pages and cleaner code and works more. I do something like this in my CSS doc...

PHP Code: [ Select ]
<?php
$FireFox = (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox') !== FALSE);
$MSIE7 = (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') !== FALSE);
if($FireFox || $MSIE7)
{
?>
//css
<?php
}
?>
  1. <?php
  2. $FireFox = (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox') !== FALSE);
  3. $MSIE7 = (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') !== FALSE);
  4. if($FireFox || $MSIE7)
  5. {
  6. ?>
  7. //css
  8. <?php
  9. }
  10. ?>


You're actually better off calling your CSS page like style.css.php and then sending this before any output:
PHP Code: [ Select ]
<?php
header('Content-type: text/css');
$FireFox = (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox') !== FALSE);
$MSIE7 = (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') !== FALSE);
if($FireFox || $MSIE7)
{
?>
style { font-size: 5px; }
.fake_class { color: #FF0000; }
/* etc... */
<?php
}
?>
  1. <?php
  2. header('Content-type: text/css');
  3. $FireFox = (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox') !== FALSE);
  4. $MSIE7 = (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') !== FALSE);
  5. if($FireFox || $MSIE7)
  6. {
  7. ?>
  8. style { font-size: 5px; }
  9. .fake_class { color: #FF0000; }
  10. /* etc... */
  11. <?php
  12. }
  13. ?>


Then you can just have the same file for all browsers with <link>. Oh if you're really picky you could use stripos instead of strpos too, I think it might be faster.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 65 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.