0

I need to explode some content like this :

For example this is my content :

[A] [C#m] [Dm] [Dm]

how can I explode the charecters between [ ] and put them in a array ?

Pablo
  • 561
  • 4
  • 16

2 Answers2

2

You can use preg_match_all to achieve that:

$content = '[A] [C#m] [Dm] [Dm]';
preg_match_all("/\[(.*?)\]/", $content, $matches);

$result = $matches[1];

The result will be an array of strings.

Andrii H.
  • 1,682
  • 3
  • 20
  • 40
0

For the example where they are adjacent ][, you could explode after trimming [ and ]. Your example has a space in between ] and [:

$result = explode('] [', trim($string, '[]'));
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87