N
N
Nikita Dergachov2018-07-05 13:10:35
PHP
Nikita Dergachov, 2018-07-05 13:10:35

How to select value in curly brackets?

There is a line

Text text {FOO} text text {BAR} text
how to select a value from curly braces to get an array of the form['FOO', 'BAR']

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2018-07-05
@vanillathunder

$text = 'Text text {FOO} text text {BAR} text';

if(preg_match_all('/\{(.*?)\}/', $text, $matches)) {
    print_r($matches[1]);
    exit;
}

S
Stalker_RED, 2018-07-05
@Stalker_RED

/\{(.+?)\}/g
https://regex101.com/r/wskD0f/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question