Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用preg_replace替换双引号之间的逗号_Php_Explode - Fatal编程技术网

Php 使用preg_replace替换双引号之间的逗号

Php 使用preg_replace替换双引号之间的逗号,php,explode,Php,Explode,我有一个像这样的csv文件 Number,Name,UG College,UG University,PG College,PG University 1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali" 在读取文件时,我只想在双引号内替换逗号 提前感谢。它假设字符串采用什么编码?preg函数得到了一个u修饰符来设置UTF8,请参见其他函数是bin

我有一个像这样的csv文件

Number,Name,UG College,UG University,PG College,PG University
1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali"
在读取文件时,我只想在双引号内替换逗号


提前感谢。

它假设字符串采用什么编码?preg函数得到了一个
u
修饰符来设置UTF8,请参见其他函数是binary-safecreate\u。php 7.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;