使用PHP爆炸字符串

时间:2014-02-05 15:11:12

标签: php arrays

如何分解此数组值:

$row = array(
[0] = 1,1,Carlyle,Rogers,1,"Carlyle, Rogers",0000-00-00,,carlyle.rogers@stafford-trust.com,,non premium)

我试过这段代码

$values         =   explode(',', $row[0]);

并给我错误的输出:

Array (
   [0] => 1
   [1] => 1
   [2] => Carlyle
   [3] => Rogers
   [4] => 1
   [5] => "Carlyle
   [6] => Rogers"
   [7] => 0000-00-00
   [8] => 
   [9] => carlyle.rogers@stafford-trust.com
   [10] => 
   [11] => non premium
)

我想要的是输出必须像这样:

Array (
   [0] => 1
   [1] => 1
   [2] => Carlyle
   [3] => Rogers
   [4] => 1
   [5] => "Carlyle, Rogers"
   [6] => 0000-00-00
   [7] => 
   [8] => carlyle.rogers@stafford-trust.com
   [9] => 
   [10] => non premium
)

1 个答案:

答案 0 :(得分:5)

您无法使用explode,因为您的输入似乎是CSV - 已格式化且explode对该“格式”一无所知。请改用str_getcsv

$values = str_getcsv($row[0]);