Answer the question
In order to leave comments, you need to log in
How to find text in a variable (string)?
Good day, friends. I have a variable (string) like this "10 01 32 05 54".
I need to find in this string all the numbers from 01 to 09 , that is, 01 and 05 are suitable for me .
Can you please tell me how to search in a variable by several conditions at the same time? (find 01 and 02 and 03 etc. )
Answer the question
In order to leave comments, you need to log in
$re = '/(?:[^\d]|^)([0][1-9])(?:[^\d]|$)/';
$str = '10 01 32 05 54';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
$string = "10 01 32 05 54";
$numbers = explode(" ", $string);
$filtered = array_filter($numbers , function($number) {
return in_array($number, ["01", "02", "03", "04", "05"]);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question