I have a string with color names, separated by commas or | characters:
$s = 'Blue | Red (light, dark) | Green, Yellow, Brown';
I need to convert it to array:
$colors = preg_split('![\|,]!', $s);
But the result is:
Array
(
[0] => Blue
[1] => Red (light
[2] => dark)
[3] => Green
[4] => Yellow
[5] => Brown
)
It splits the "light, dark" string with comma. I'd like to split with commas not inside parentheses. Desired result:
Array
(
[0] => Blue
[1] => Red (light, dark)
[2] => Green
[3] => Yellow
[4] => Brown
)
How can I solve it?