开发者 | steve.barnett |
---|---|
更新时间 | 2012年9月11日 00:46 |
PHP版本: | 3.0 及以上 |
WordPress版本: | 3.0 |
版权: | GPLv2 or later |
In order to access the features you need to use the $ua
object that is automatically created with the inclusion of Detector in your application. Use the $ua
object in a similar way that you would have used the Modernizr
object on the client-side:
global $ua;
// your script
if ($ua->svg) {
...
} elseif ($ua->canvas) {
...
}
See the full list of browser features that are tested by Modernizr and available with Detector. All of the features tested with ua-parser-php are also available from the $ua
variable (e.g. $ua->isMobile
or $ua->browserFull
)
Some features, (in particular video
, audio
, input
, and inputtypes
) have sub-features, so these are available as nested PHP objects:
if ($ua->inputtypes->search) {
print "<input type='search' ...";
} else {
print "<input type='text' ...";
}
All features are returned as integer 1
or 0
for true
or false
, so they can be used in logical evaluations in PHP. Sub-features can return 1
, 0
, or a real value (e.g. screen width).