0

I have String like this

$string ="this is test {username} ,{password@123} and Other {asdfg@#$}"

I want this string as array format as follows

[1] => Array
        (
            [0] => username
            [1] => password@123
            [2] => asdfg@#$
        )
halfer
  • 19,471
  • 17
  • 87
  • 173
sv.sasi
  • 7
  • 4

2 Answers2

0
(?<={)[^}]+(?=})

Try this.This should work.

$re = "/(?<={)[^}]+(?=})/mi";
$str = "this is test {username} ,{password@123} and Other {asdfg@#\$}";

preg_match_all($re, $str, $matches);
vks
  • 65,133
  • 10
  • 87
  • 119
0
$re = "/\{(.*?)\}/";
$str = "this is test {username} ,{password@123} and Other {asdfg@#\$}";

preg_match_all($re, $str, $matches);

print_r($matches);

this gives what you want