Here's my way:
$string = "'test', 'test', 'test, test, kk', NULL, NULL, NULL, 123456789012, 0, '2017-02-17', FALSE";
$array_tmp = explode(', ', $string);
$array = array();
$index_buffer = NULL;
$index = 0;
foreach($array_tmp as $value) {
// Check if we need to append to buffered entry
if($index_buffer !== NULL){
$array[$index_buffer] .= ', ' . $value;
if($value[strlen($value) - 1] === "'"){
$index_buffer = NULL;
}
continue;
}
// Check if it's not ended string
if(is_string($value) && $value[0] === "'" && $value[strlen($value) - 1] !== "'"){
// It is not ended, set this index as buffer
$index_buffer = $index;
}
// Save value
$array[$index] = $value;
$index++;
}
echo '<pre>' . print_r($array, true);
Output:
Array
(
[0] => 'test'
[1] => 'test'
[2] => 'test, test, kk'
[3] => NULL
[4] => NULL
[5] => NULL
[6] => 123456789012
[7] => 0
[8] => '2017-02-17'
[9] => FALSE
)
Or this may be more suitable but you lose quotes, and I guess, if your input string doesn't respect all csv standards, you could have border effects since str_getcsv handles more things than this quote issue:
str_getcsv($string, ",", "'");