Created
April 13, 2020 18:27
-
-
Save marcus-at-localhost/5c93f06ddb32e35400cbd2fc4a0f5f51 to your computer and use it in GitHub Desktop.
[Split by Comma but not if in Parenthesis] #regex #split #array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filters = "1,2,4,(5,6,7),8;9"; | |
var_dump(preg_split("~[,|;](?![^(]*\\))~", $filters)); | |
/* | |
array (size=6) | |
0 => string '1' (length=1) | |
1 => string '2' (length=1) | |
2 => string '4' (length=1) | |
3 => string '(5,6,7)' (length=7) | |
4 => string '8' (length=1) | |
5 => string '9' (length=1) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment