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 7042601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:17+00:00 2026-05-28T02:11:17+00:00

I have a list of Mobile devices that I’m using to display content correctly.

  • 0

I have a list of Mobile devices that I’m using to display content correctly. The depreciated function looks like this:

function detectPDA($query){
    $browserAgent = $_SERVER['HTTP_USER_AGENT'];
    $userAgents = $this->getBrowserAgentsToDetect(); // comma separated list of devices
    foreach ( $userAgents as $userAgent ) {
        if(eregi($userAgent,$browserAgent)){
            if(eregi("iphone",$browserAgent) || eregi("ipod",$browserAgent) ){
                $this->iphone = true;
            }else{
                $this->pda = true;
            }
        }
    }
}

What is the correct way to replace the eregi functions?

  • 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-28T02:11:18+00:00Added an answer on May 28, 2026 at 2:11 am

    If all the pattern strings ($userAgent and iphone) can be trusted not to contain special regex chars (()[]!|.^${}?*+), then you just surround the eregi regex with slashes (/) and add an i after the last slash (which means “case insensitive”).

    So:

    eregi($userAgent,$browserAgent) --> preg_match("/$userAgent/i",$browserAgent)
    eregi("iphone",$browserAgent)   --> preg_match('/iphone/i',$browserAgent)
    

    However, are you just trying to match $userAgent as-is within $browserAgent? For example, if a particular $userAgent was foo.bar, would you want the . to match a literal period, or would you want to interpret it in its regex sense (“match any character”)?

    If the former, I’d suggest you forgo regex entirely and use stripos($haystack,$needle), which searches for the string $needle in $haystack (case-insensitive). Then you don’t need to worry about (say) an asterisk in $userAgent being interpreted in the regex sense instead of the literal sense.

    If you do use stripos don’t forget it can return a 0 which would evaluate to false, so you need to use === false or !== false (see the documentation I linked).

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

Sidebar

Related Questions

I have a jquery mobile list. This list is populated with data. I want
I have to display different views for mobile devices and I want to provide
I have a mobile app that I developed using PhoneGap (and html/css/javascript) and there
I have a list of mobile phone $numbers and i have to change them,
I'm making a shopping list mobile application (Java ME) and i have two classes;
I have a list view in jQuery Mobile with delete buttons in them. <ul
In mobile, the internet is slow. If I have a list of 500 images,
i have list of rows that user select and i want to delete them,
I have a bat file that I am using to try and register Mobilink
I have a data set which has a list of user agents and devices

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.