PHP: How can I explode a string by commas, but not wheres the commas are within quotes?

前端 未结 3 1471
情话喂你
情话喂你 2020-11-28 11:44

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 l         


        
3条回答
  •  無奈伤痛
    2020-11-28 12:24

    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
    )
    

提交回复
热议问题