Answer the question
In order to leave comments, you need to log in
How to get text between certain characters?
Hello!
There is a line "s2(off)"
How to get the number after the "s" sign using the PHP method, provided that the number can be any value, and get the text in the arches under the same condition? Write the number and text into different variables.
Answer the question
In order to leave comments, you need to log in
$str = 's2(off)';
if (preg_match('/s(?P<number>\d+)\((?P<word>\w+)\)/', $str, $matches)) {
var_dump($matches);
} else {
echo 'Совпадения не найдены';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question