I have a long string, like this:
11070, 'EP_LQ-630', 'LQ-630, 24 pin, A4, 360 cps, USB 1.1&LPT', NULL, 6438, 1, 45, 1, 5184, 0, 20, NULL, NULL, 432, 1, 5088, 0, 424, 1, 1, 4, 1, NULL, NULL, NULL, NULL, NULL, NULL, 3, NULL, NULL, NULL, 370, 1, 369, 1, 368, 1, 367, 1, NULL, NULL, NULL, NULL, NULL, 1, '8443', NULL, NULL, NULL, '07.12.2011 18:16:28', NULL, NULL, '8471604', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 366, 1, ';6438;6432;4873;', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
This is a part of a SQL Insert query, and comma separated values are columns.
How can I explode this string by columns, if I have in the third columns a string, which also contains commas?
You can use the str_getcsv
function to parse a comma-separated list of values:
$parsed_array = str_getcsv($string, ',', "'"); //Return value: array
// Separated by : , (comma)
// Enclosused by: ' (single quote)