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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:49:56+00:00 2026-06-15T13:49:56+00:00

Here is an example string: 60 reviews from 12 people, 20% of users (Let’s

  • 0

Here is an example string:

“60 reviews from 12 people, 20% of users”
(Let’s call it $v)

I have been using preg_match_all to get an array with all the numbers

$pattern = '!\d+!';
preg_match_all($pattern, $v, $matches, PREG_SET_ORDER); 

The result I get is:

Array
(
    [0] => Array
        (
            [0] => 60
        )
    [1] => Array
        (
            [0] => 12
        )
    [2] => Array
        (
            [0] => 20
        )
)

But despite trying for some time I haven’t been able to get what I want. What I want is this:

Array
(
    [0] => 60
    [1] => 12
    [2] => 20
)

Maybe should I be using preg_match instead? but with preg_match I only get one value… Or maybe along with a loop? It looks like an ugly hack… There should be a profesional way out there… Thanks in advance to PHP experts! 😉

  • 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-15T13:49:57+00:00Added an answer on June 15, 2026 at 1:49 pm

    Presuming the format always stays the same, you can do the following:

    <?php
    
        // Input string/line
        $v = "60 reviews from 12 people, 20% of users";
    
        // Match regex (0-9; min 1 or max unlimited numbers)
        preg_match_all("/[0-9]{1,}/", $v, $matches);
    
        // Remove/sub key
        $matches = $matches[0];
    
        // Echo out
        print_r($matches);
    
    ?>
    

    This will output:

     Array ( 
           [0] => 60     // < Access using $matches[0]
           [1] => 12     // < Access using $matches[1]
           [2] => 20     // < Access using $matches[2]
     )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the problem. I ,for example,have a string 2500.Its converted from byte array into
Example: here is the string: blablabla123:550:404:487blablabla500:488:474:401blablablabla here is what I'm using: string reg =
UPDATE 1: Here is the full code behind from the downloaded example, unedited: using
here is my problem I have the following array (for example) string[] arr =
Here is an example that outputs 6 : public static void main(String[] args) {
For example, here is a string representing an expression: var str = 'total =
Just some example code here, but I have lists of strings that I want
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
Here an example http://jsfiddle.net/7aVXc/ Let' say current image height is 400px . How do
For example I have a string that looks like the following: var example_string =

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.