-1

" " の間の "," デリミタのみを削除したい。例:"Alibris: Books, Music, & Movies"

1行目の出力は

256,2653,"Alibris: Books  Music  & Movies",50263394,05/14/2013,07:44,50263394,114.85,1,5.74,05/14/2013,08:10

配列の例はこちら

Array
(
    [0] => 256,2653,"Alibris: Books, Music, & Movies",50263394,05/14/2013,07:44,50263394,114.85,1,5.74,05/14/2013,08:10,
    [1] => 256,2653,"Alibris: Books, Music, & Movies",50327805,05/21/2013,23:03,50327805,-6.99,1,-0.35,05/22/2013,07:10,
    [2] => 256,2653,"Alibris: Books, Music, & Movies",50327805,05/21/2013,23:03,50327805,6.99,1,0.35,05/22/2013,00:10,
    [3] => 527,36777,BuySKU,920130525042340263061,05/24/2013,20:25,1390043,"1,170.73",11,58.54,05/24/2013,20:55,
)
4

3 に答える 3

1

このようにできます

,(?!([^"]*"[^"]*"[^"]*)+$|[^"]*$)

空の文字列に置き換えます

これは、先に奇数がある場合にのみ一致します。したがって、間にある場合に"一致します,"

デモ

だから、それは

$pattern = "/,(?!([^\"]*\"[^\"]*\"[^\"]*)+$|[^\"]*$)/"; 
$replace = ""; 
$line = preg_replace($pattern,$replace,$line); 

,外用のみに分割したい"場合

 ,(?=([^"]*"[^"]*"[^"]*)+$|[^"]*$)

だからそうなるだろう

preg_split('/,(?=([^\"]*\"[^\"]*\"[^\"]*)+$|[^\"]*$)/', $text);
于 2013-07-02T04:44:52.870 に答える