如何将 csv 文件中的分隔符(“,”,“。”,“|”)更改为逗号(“,”)
How to change delimiters (",", ".", "|" ) in csv file to comma (",")
有一个日文格式的 CSV 文件,其中包含多个分隔符,例如日文逗号、点、日文 AND 标记。
那就是下面用粗体字(·dd.)表示的。我必须更改为逗号。
009M051,105,造作工事(分離),@E53405,藤本建設,1,1,1,1,1,1,1,1,1,1,1,防水・チェック,,,,,WEB
009M051,103,基礎工事(分離),@E15142,㈱晃和建設,1,1,1,1,1,1,1,0,0,0,1,13、14-1,,,,,WEB
009M051,344,外構工事,@E21502,桜井ジューキ㈱,1,1,1,1,1,1,1,0,0,0,1,A.B,,,,,WEB
需要像
这样的输出
009M051,105,造作工事(分離),@E53405,藤本建設,1,1,1,1,1,1,1,1,1,1,1,防水,チェック,,,,,WEB
009M051,103,基礎工事(分離),@E15142,㈱晃和建設,1,1,1,1,1,1,1,0,0,0,1,13,14-1,,,,,WEB
009M051,344,外構工事,@E21502,桜井ジューキ㈱,1,1,1,1,1,1,1,0,0,0,1,A,B,,,,,WEB
给我一些使用 PHP 或 VBA 进行更改的想法。提前致谢...
如果您的 csv 文件名为 1.csv 并且其中包含以下内容:
009M051,105,收尾工程(分离),@E53405,藤本建设,1,1,1,1,1,1,1,1,1,1,1,防水/检查, , WEB 009M051, 103, foundation work (separation), @E15142, Kowa Construction Co., Ltd., 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 13, 14-1 , ,WEB 009M051,344,外部施工,@E21502,樱井重机株式会社,1,1,1,1,1,1,1,0,0,0,1,A.B, 网页
你可以这样做:
<?php
$file = '1.csv';
$strings = file_get_contents($file);
$search = array('・', '、', '.');
$strings = str_replace($search, ',', $strings);
file_put_contents($file, $strings);
?>
试试这个...
iconv : http://php.net/manual/en/function.iconv.php
字符集:http://www.gnu.org/software/libiconv/
如果您正在使用 fputcsv 尝试传递所有参数以获得更好的准确性
int fputcsv ( $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
有一个日文格式的 CSV 文件,其中包含多个分隔符,例如日文逗号、点、日文 AND 标记。 那就是下面用粗体字(·dd.)表示的。我必须更改为逗号。
009M051,105,造作工事(分離),@E53405,藤本建設,1,1,1,1,1,1,1,1,1,1,1,防水・チェック,,,,,WEB 009M051,103,基礎工事(分離),@E15142,㈱晃和建設,1,1,1,1,1,1,1,0,0,0,1,13、14-1,,,,,WEB 009M051,344,外構工事,@E21502,桜井ジューキ㈱,1,1,1,1,1,1,1,0,0,0,1,A.B,,,,,WEB
需要像
这样的输出009M051,105,造作工事(分離),@E53405,藤本建設,1,1,1,1,1,1,1,1,1,1,1,防水,チェック,,,,,WEB 009M051,103,基礎工事(分離),@E15142,㈱晃和建設,1,1,1,1,1,1,1,0,0,0,1,13,14-1,,,,,WEB 009M051,344,外構工事,@E21502,桜井ジューキ㈱,1,1,1,1,1,1,1,0,0,0,1,A,B,,,,,WEB
给我一些使用 PHP 或 VBA 进行更改的想法。提前致谢...
如果您的 csv 文件名为 1.csv 并且其中包含以下内容:
009M051,105,收尾工程(分离),@E53405,藤本建设,1,1,1,1,1,1,1,1,1,1,1,防水/检查, , WEB 009M051, 103, foundation work (separation), @E15142, Kowa Construction Co., Ltd., 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 13, 14-1 , ,WEB 009M051,344,外部施工,@E21502,樱井重机株式会社,1,1,1,1,1,1,1,0,0,0,1,A.B, 网页
你可以这样做:
<?php
$file = '1.csv';
$strings = file_get_contents($file);
$search = array('・', '、', '.');
$strings = str_replace($search, ',', $strings);
file_put_contents($file, $strings);
?>
试试这个...
iconv : http://php.net/manual/en/function.iconv.php
字符集:http://www.gnu.org/software/libiconv/
如果您正在使用 fputcsv 尝试传递所有参数以获得更好的准确性
int fputcsv ( $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )