欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

如何使用正则表达式去掉被双引号包裹的数字两边的双引号

程序员文章站 2024-01-28 12:28:40
...
从某云导出数据库表为CSV格式,发现bigint字段两边也被加上了双引号,不应该啊不应该,如何去掉呢?

示例记录:

"31189","aaaa","$P$BFMnptFob/7bmU2o***PNqorSMKzLs0","aaaa","aaa@qq.com","","2015-02-27 02:18:54","","0","oo","0000-00-00"

"31191","bbbb","$P$BeRmQEYPfnOfKrKpF***9osOe3v0aq/","bbb","bbb@qq.com","","2015-02-27 04:23:52","","0","bbb","0000-00-00"

回复内容:

从某云导出数据库表为CSV格式,发现bigint字段两边也被加上了双引号,不应该啊不应该,如何去掉呢?

示例记录:

"31189","aaaa","$P$BFMnptFob/7bmU2o***PNqorSMKzLs0","aaaa","aaa@qq.com","","2015-02-27 02:18:54","","0","oo","0000-00-00"

"31191","bbbb","$P$BeRmQEYPfnOfKrKpF***9osOe3v0aq/","bbb","bbb@qq.com","","2015-02-27 04:23:52","","0","bbb","0000-00-00"

为啥要去掉php 有对应函数
http://php.net/str_getcsv

昂,已经弄了个php版本的处理了

function fucking_aliyun_rds($line){

    if(!$line) return;
    $line=(string)$line;

    $pattern='/^\"\d{1,5}\"/';
    $int=$replacement=false;
    if(preg_match($pattern, $line, $matches)){

        $int=(int)str_replace('"', '', $matches[0]);
    }else{
        return $line;
    }

    if($int){
        $replacement = $int;
        $line=preg_replace('""', '',$line);
        $b=preg_replace($pattern, $replacement, $line);

    }
    $b.="\t";
    return $b;

}

$f = fopen ("wp_users.txt", "r");
$ln= 0;
while (! feof ($f)) {
$line= fgets ($f);
/* ++$ln;/
/
printf ( $ln);*/
if ($line===FALSE) {
}
else{

    $a=fucking_aliyun_rds($line);
    echo $a;


}

}
fclose ($f);

相关标签: 正则表达式 php