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,824
  • 17
  • 99
  • 186
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
  • 67,027
  • 10
  • 91
  • 124
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