I need to explode my string input into an array at the commas. However the string contains commas inside quotes.
Input:
$line = 'TRUE','59','A large number is 10,000';
$linearray = explode(",",$line);
$linemysql = implode("','",$linearray);
Returns $linemysql as:
'TRUE','59','A large number is 10','000'
How can I go about accomplishing this, with the explode ignoring the commas inside the quote marks?
Since you are using comma seperated values, you can use str_getcsv
.
str_getcsv($line, ",", "'");
Will return:
Array
(
[0] => TRUE
[1] => 59
[2] => A large number is 10,000
)