wezom-agency / browserizr
Browserizr is tiny library, that detects your browser
Installs: 5 460
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/wezom-agency/browserizr
README
Browserizr is tiny library, that detects your browser
with testing$_SERVER['HTTP_USER_AGENT'].
that is PHP port of the JavaScript library WezomAgency/Browserizr
with several limitations...
Install
composer require wezom-agency/browserizr
Prev versions
please read:
API
List of built-in tests
Browserizr::detect()->isAndroid()Browserizr::detect()->isAndroid3()Browserizr::detect()->isAndroid4()Browserizr::detect()->isAndroid5()Browserizr::detect()->isAndroid6()Browserizr::detect()->isAndroid7()Browserizr::detect()->isAndroid8()Browserizr::detect()->isBlackberry()Browserizr::detect()->isBlackberry10()Browserizr::detect()->isEdge()Browserizr::detect()->isEdgeAndroid()Browserizr::detect()->isEdgeIOS()Browserizr::detect()->isIE()Browserizr::detect()->isIE8()Browserizr::detect()->isIE9()Browserizr::detect()->isIE10()Browserizr::detect()->isIE11()Browserizr::detect()->isIPad()Browserizr::detect()->isIPod()Browserizr::detect()->isIPhone()Browserizr::detect()->isWindowsPhone()Browserizr::detect()->isMoz()Browserizr::detect()->isOpera()Browserizr::detect()->isSafari()Browserizr::detect()->isChrome()Browserizr::detect()->isMobile()Browserizr::detect()->isDesktop()
Usage examples:
<?php use WezomAgency\Browserizr; ?> <?php if (Browserizr::detect()->isChrome()) { ?> <div class="alert">Chrome is here, baby!!!</div> <?php } ?>
Generate css classes
Browserizr::detect()->cssClasses($tests, $cssPrefix = "", $toString = true): array|string
Create string with CSS classes
Parameters:
| Name | Data type | Default value | Description |
|---|---|---|---|
$tests |
string[] |
array of wanted tests, each name - test name without is prefix |
|
$cssPrefix |
string |
"" |
custom prefix for CSS class name |
$toString |
bool |
true |
implode resulted array and return as string; |
Usage examples:
<?php use WezomAgency\Browserizr; ?> <!DOCTYPE html> <html class="<?= Browserizr::detect()->cssClasses(['Mobile', 'Desktop']); ?>"> <head>...</head> <body>...</body> </html> <!-- render output --> <html class="is-mobile is-not-desktop"><!-- if mobile device --> <html class="is-not-mobile is-desktop"><!-- if desktop -->
<?php use WezomAgency\Browserizr; ?> <!DOCTYPE html> <html class="<?= Browserizr::detect()->cssClasses(['Mobile', 'Desktop'], 'browserizr-'); ?>"> <head>...</head> <body>...</body> </html> <!-- render output --> <html class="browserizr-is-mobile browserizr-is-not-desktop"><!-- if mobile device --> <html class="browserizr-is-not-mobile browserizr-is-desktop"><!-- if desktop -->
<?php use WezomAgency\Browserizr; $myCssClasses = Browserizr::detect()->cssClasses(['Mobile', 'Desktop'], '', false); // ... work with array, e.g. array_push() or array_combine() or whatever you want ?>
Set custom UserAgent
by default Browserizr use $_SERVER['HTTP_USER_AGENT']
you can set own string for UserAgent.
Note
if you needed to change agent - you must do it before use the Browserizr tests
<?php use WezomAgency\Browserizr; Browserizr::detect()->setUserAgent('my own UserAgent string'); // then can test your browser correctly var_export(Browserizr::detect()->isWindowsPhone());