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

  • SEARCH
  • Home
  • 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 8355681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:56:18+00:00 2026-06-09T09:56:18+00:00

I need to find the version of Chrome using PHP. I coded this: $ua

  • 0

I need to find the version of Chrome using PHP.

I coded this:

$ua = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.60 Safari/537.1";
preg_match( "#Chrome/([0-9]{2})#", $ua, $match );
print_r($match);

Which returns:

Array
(
    [0] => Chrome/21
    [1] => 21
)

I have two questions:

Will this work on all chrome browsers? (because the $ua is my own user agent.

Also how can I make the pattern so it returns only “21” instead of “Chrome/21” and “21” in an array?

  • 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-06-09T09:56:19+00:00Added an answer on June 9, 2026 at 9:56 am

    This WON’T work on all Chrome browsers. What if it’s Chrome Version 3? Or Chrome Version 2245?

    See me.

    What I would do is change your Regular Expression to the following:

    preg_match( "#Chrome/(.+?)\.#", $ua, $match );
    

    This returns the same thing as what you have now, but it also works with any-digit versions.

    array (
      0 => 'Chrome/21.',
      1 => '21',
    )
    

    You can test this here.

    As for your second question, you cannot modify preg_match() to return the value like that. Simply setting $match = $match[1] works fine, though, and is completely acceptable!

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

Sidebar

Related Questions

I need to find some strings that the current version of Windows is using.
I need to find mobile OS name and OS version programmatically: like Symbian s40
I often have a need to find something I coded in an old version
I need to find a flexible solution for access control in PHP. In the
I need to find the coordinates of windows open even when they are not
I need to find a way to get actual page size in Google Chrome.
How to find version of an application installed, using c#. Is there a way
I need to find a child control in a Windows Forms panel. I was
Using a ruby file (or any rake facility) I need to find out if
I need to find out the version of an assembly deployed to an SQL

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.