2

我有一个这样的csv文件

Number,Name,UG College,UG University,PG College,PG University
1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali"

在阅读文件时,我只想在双引号内替换逗号。

提前致谢 。

4

1 回答 1

2
$string = '1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali"';

$string = preg_replace_callback(
        '|"[^"]+"|',
        create_function(
            // single quotes are essential here,
            // or alternative escape all $ as \$
            '$matches',
            'return str_replace(\',\',\'*comma*\',$matches[0]);'
        ),$string );
$array = explode(',',$string);
$array = str_replace('*comma*',',',$array);
print_r($array);       
exit;
于 2013-05-10T13:25:28.360 回答