V
V
voit_v2015-11-25 20:29:11
PHP
voit_v, 2015-11-25 20:29:11

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

2 answer(s)
M
Muhammad, 2015-11-25
@voit_v

$str = 's2(off)';

if (preg_match('/s(?P<number>\d+)\((?P<word>\w+)\)/', $str, $matches)) {
    var_dump($matches);
} else {
    echo 'Совпадения не найдены';
}

A
Alexey Ukolov, 2015-11-25
@alexey-m-ukolov

php.net/manual/en/function.preg-match.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question