Skip to content

Instantly share code, notes, and snippets.

@matthewpennell
Created May 15, 2011 14:25
Show Gist options
  • Save matthewpennell/973198 to your computer and use it in GitHub Desktop.
Save matthewpennell/973198 to your computer and use it in GitHub Desktop.
Browser sniffing with regular expressions in PHP
<?php
# Set browser and version environment variables based on the visitor's browser
preg_match_all("/(Opera|Chrome|Version|Firefox|MSIE)[\/|\s](\d+)/", $_SERVER['HTTP_USER_AGENT'], $matches, PREG_SET_ORDER);
list($browser, $version) = array($matches[0][1], $matches[0][2]);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment