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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:05:32+00:00 2026-05-30T23:05:32+00:00

Just wondering if you can help me out a bit with a little task

  • 0

Just wondering if you can help me out a bit with a little task I’m trying to do in php.

I have text that looks something like this in a file:

    (random html)
    ...
    <OPTION VALUE="195" SELECTED>Physical Chem  
    <OPTION VALUE="239">Physical Chem Lab II  
    <OPTION VALUE="555">Physical Chem for Engineers            
    ...
    (random html)

I want to return the # value of the option values ignoring everything else.
For example, in the above case I would want 195, 239 & 555 returned, nothing else like “Option Value=”.

I am having trouble doing this in PHP. So far I have this:

preg_match("/OPTION VALUE=\"([0-9]*)/", $data, $matches);
        print_r($matches);  

With the return value of this:

Array ( [0] => OPTION VALUE=”195[1] => 195) Array ( [0] => OPTION VALUE=”195[1] => 195)

How can I return the all the #’s?

I’m a newbie at pattern matching and tutorials I’ve read haven’t helped much, so thanks a ton!

  • 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-30T23:05:34+00:00Added an answer on May 30, 2026 at 11:05 pm

    preg_match will return an array containing only the first match. The first index of the array wil return a match for the full regular expression, the second one matches the capture group in the parentheses, try the following to get a concept of how this works:

    preg_match("/(OPTION) VALUE=\"([0-9]*)/", $data, $matches);
        print_r($matches);
    

    You will see that it outputs the following:

    Array
    (
        [0] => OPTION VALUE="195
        [1] => OPTION
        [2] => 195
    )
    

    Array[0] contains data of the full match, array [1] contains data from the first capture group (OPTION) and array[2] contains data from the second capture group ([0-9]*).

    In order to match more than one occurrence, you need to use the preg_match_all function. If we apply this to your original code like so:

    preg_match_all("/OPTION VALUE=\"([0-9]*)/", $data, $matches);
        print_r($matches);
    

    We get:

    Array
    (
        [0] => Array
            (
                [0] => OPTION VALUE="195
                [1] => OPTION VALUE="239
                [2] => OPTION VALUE="555
            )
    
        [1] => Array
            (
                [0] => 195
                [1] => 239
                [2] => 555
            )
    
    )
    

    I hope this makes things clear!

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

Sidebar

Related Questions

Just wondering if you can help me out with something. I have a string
Just wondering if someone can help me out with this quickly. I have a
I'm just wondering how I can read a text file in php, I'd like
Just wondering if someone can help me figure out why my menu is doing
I have a small problem and wondering if someone can help me out. I'm
Just wondering if anyone can help me with a little programming math i'm having
Just wondering how I can paste an object after I have selected it in
I'm wondering if anyone can help me out with some Canvas. I'm pretty new
I am wondering if anyone can help me out with parsing out data for
Wondering if anyone can help with this. I have a table with some fixed

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.