我有一个这样的csv文件
Number,Name,UG College,UG University,PG College,PG University
1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali"
在阅读文件时,我只想在双引号内替换逗号。
提前致谢 。
$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;