PHP Regex - comma delimited string, IGNORE comma between tags
2 answers
Based on this line, you can use the following ...
$results = preg_split('/(?:<[^>]*>)?\K,/', $str);
print_r($results);
Output
Array
(
[0] => <[return date("Y-m-d", strtotime("yesterday"));]>
[1] => <[return "cool!";]>
[2] => TRUE
[3] => foo
)
Or, of course, you could match everything instead of using split.
preg_match_all('/<[^>]+>|[^><,]+/', $str, $matches);
+4
source to share