Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Forked from gavinblair/index.php
Created Jun 10, 2010
Embed
What would you like to do?
mobile browser detection
<?php
$mobiles = array(
'iphone','ipod','android','blackberry',//and so on
);
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if($match = preg_match('/('.implode('|',$mobiles).')/', $agent)){
echo 'mobile';
//include mobile stuff here
} else {
echo 'not mobile';
//do normal stuffs
}
@gavinblair
Copy link

gavinblair commented Jun 10, 2010

line 5: strotolower -> strtolower :)

seems to work, and is much nicer to read. thanks!

@SeanJA
Copy link
Author

SeanJA commented Jun 10, 2010

Right... erm... I meant that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment