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 ?
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.
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, '[]'));