Skip to content

Instantly share code, notes, and snippets.

@peoii
Last active September 24, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peoii/0385ccce9dc7138ca724 to your computer and use it in GitHub Desktop.
Save peoii/0385ccce9dc7138ca724 to your computer and use it in GitHub Desktop.
A simple script to convert a directory of CSV files from tab delimited to pipe delimited
<?php
$dir=opendir('./');
while(($entry = readdir($dir)) !== false) {
$fname = preg_split("/\./",$entry);
if(strcasecmp($fname[1],"xls") !== 0) {
continue;
}
$rows = file($fname[0].'.xls');
$fp = fopen($fname[0].'.csv', 'w');
foreach($rows as $row) {
$data = str_replace("\t", "|", $row);
fwrite($fp, $data);
}
fclose($fp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment