一个小技巧,发现php可以这么写。。
<?php
function a()
{
return true;
}
function b()
{
echo ‘test’;
}
a() && b();
?>
这样会输出test a() return false的时候,会不输出test
具体怎么用?比如这个函数~~
<?php
function isBuggyIe() {
$ua = $_SERVER['HTTP_USER_AGENT'];
// quick escape for non-IEs
if (0 !== strpos($ua, ‘Mozilla/4.0 (compatible; MSIE ‘)
|| false !== strpos($ua, ‘Opera’)) {
return false;
}
// no regex = faaast
$version = (float)substr($ua, 30);
return (
$version < 6
|| ($version == 6 && false === strpos($ua, ‘SV1′))
);
}
// usage:
isBuggyIe() && ob_start(“ob_gzhandler”);
?>
嗯嗯。。。支持压缩的浏览器,才压缩,不支持的,就不压缩,对咯。。
当然啦,我还是支持再apache或者nginx层面配置这个。。。php吗,就应该踏踏实实做自己应该做的事情~~~
Recent Comments