Tuesday, August 3, 2010

If you use the explode user agent to get the mobile phone model

f you use the explode user agent to get the mobile phone model, you will find out that on most new nokia phones you will get Mozilla instaed of NokiaN95 etc, here is a small function which helps to get the phone model from useragent.


PHP Code:
function mobile_phone($_mob_ua)
{
      
$_position=strpos($_mob_ua,"Nokia");
       if(
$_position)$_mob_ua substr($_mob_ua$_position,25);
       else 
$_mob_ua=$_mob_ua;
      
$phone explode ('/'$_mob_ua); 
      return 
$phone[0];
}  
usage :
Code:
echo 'Best for '.mobile_phone($_SERVER['HTTP_USER_AGENT']).'
';

No comments:

Post a Comment