Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:51:37+00:00 2026-05-28T03:51:37+00:00

This maybe some simple silly thing but I can’t figure it out on my

  • 0

This maybe some simple silly thing but I can’t figure it out on my own.

I am trying to make a mobile detection script and have had great success. But upon deeper inspection I found that one of my IF clauses seems to be returning TRUE but with the wrong match.

I have this array:

private $arrAgent = array(
    'sony',
    'symbian',
    'nokia',
    'samsung',
    'mobile',
    'windows ce',
    'blackberry',
    'ericsson',
    'danger',
    'palm',
    'series60',
    'palmsource',
    'pocketpc',
    'smartphone',
    'vodafone',
    'iphone',
    'ipad',
    'android'
    );

then I have a function that will loop the array and find if it matches

private function detectMobileAgent() {

    if ($this->MobileDevice === false) {

        foreach ($this->arrAgent as $key => $value) {

            if (strpos(Server::userAgent(), $value) !== false) {
                $this->MobileDevice = true;
                // echo $value;
                break;
            }
        }
    }
}

Now the problem is that I found an error in the iPad/iPhone userAgent that prevents from me getting a clear reading.

The iPad user agent looks like this:

mozilla/5.0 (ipad; u; cpu os 4_3_2 like mac os x; en-us) applewebkit/533.17.9 (khtml, like gecko) version/5.0.2 mobile/8h7 safari/6533.18.5

I got that from a iOS simulator that comes with xCode, on my actual iPad I saw an almost identical user agent, just the OS version and safari version were different.

Now my problem is that in that user agent, the string position returns a match for ipad AND mobile, how can I get it to stop after the first string matched?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:51:37+00:00Added an answer on May 28, 2026 at 3:51 am

    It will already stop at the first string in $arrAgent that matches; that’s what the break inside the loop is doing.

    If you want to prioritize a match against ipad over one against mobile, just rearrange your $arrAgent so 'ipad' appears before 'mobile'.

    If you make sure the array is arranged with specific terms at the beginning and generic terms at the end, you’ll always get the most specific possible match returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There maybe some simlar questions to this but I can't see anything that really
This maybe a really simple question but for some reason my code isn't working.
This maybe a stupid question, but as I can not easily undo my change
maybe some one can help me with this... I have a custom search button
I'm trying to do some simple data retrieval with C# and Directory Services, but
I have a string input = "maybe (this is | that was) some ((nice
I have some C++ source code with templates maybe like this - doxygen runs
Maybe I am just over thinking this and need to write some more prototype
I am going crazy now. Googled this, thought some kind of IDE bug. Maybe
I know that this may be an amateur question but for some reason I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.