我正在开发一个WordPress主题,需要设置一个检查IE的功能。我想检查Internet Explorer 7,所以如果我使用以下代码:
<?php
if (preg_match('/\bmsie 7/i', $ua) && !preg_match('/\bopera/i', $ua))
echo 'Do Something'
?>
改为:
<!--[if lt IE 7]>
Do Something
<![endif]-->
有什么缺点吗?只是在需要时加载HTML。任何见解都将不胜感激。
编辑
发现了这篇关于用PHP的好文章:http://www.kingofdevelopers.com/php-classes/get-browser-name-version.php