This should set you on the right path
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( empty($user_agent) ) {
$is_mobile = false;
} elseif ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap|phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
echo (is_mobile) ? 'I am a mobile !' : 'I am not a mobile :(';