I need to find all 3-digit numbers in a string using PHP?

  • Thread starter Thread starter BodyBuilderPup
  • Start date Start date
B

BodyBuilderPup

Guest
Ive been trying my hardest to use PHP to look through a string and check whether any of the 3-digit numbers match the existing number.

The string for example looks like this: "107 106 104 101"

The code Im using does this:

if (preg_match('/^[0-9][0-9][0-9]$/', $selection_table_option, $list_data_to_compare)) { $options .= ' checked ';}

What I want the code to do is look in $list_data_to_compare, if it finds a 3-digit number which matches $selection_table_option (eg "107") then the statement is true.

Its not doing that, its just bringing back eveyrthing or nothing, even if I use {3}. Ive tried so many permiations IM stuck so much much!

Please help!
 
Back
Top