开发者

Extracting delimited strings from a paragraph

开发者 https://www.devze.com 2023-03-17 02:00 出处:网络
I need to get all {SOME_STRING} from a paragraph as an array. For example : Bla bla bla some {first} some string bla {second} bla bla .....

I need to get all {SOME_STRING} from a paragraph as an array. For example :

Bla bla bla some {first} some string bla {second} bla bla .....

I have to get them like this array :

$array[0] 开发者_如何转开发= "first";
$array[1] = "second";

This is the REGEX pattern for {SOME_STRING} : \{.+}

Which method can i use ?


$str = "Bla bla bla some {first} some string bla {second} bla bla .....";
$matches = array();
preg_match_all("/\{(.+?)\}/", $str, $matches);
$array = $matches[1];

var_dump($array);

Output

array(2) {
  [0]=>
  string(5) "first"
  [1]=>
  string(6) "second"
}
0

精彩评论

暂无评论...
验证码 换一张
取 消