Skip to content

Instantly share code, notes, and snippets.

@ishtaka
Last active December 29, 2015 16:59
Show Gist options
  • Select an option

  • Save ishtaka/7701267 to your computer and use it in GitHub Desktop.

Select an option

Save ishtaka/7701267 to your computer and use it in GitHub Desktop.
[PHP]Excelで作成(編集)されたCSVをPHP(UTF-8)で読み込む
<?php
/**
* CSV読み込み
*
* @access public
* @param string $path
* @retunr array $result
*/
public static function readCsv($path)
{
if (!is_readable($path)) return false;
$data = @file_get_contents($path);
if (!$data) {
return false;
}
$data = mb_convert_encoding($data, 'UTF-8', 'sjis-win');
$temp = tmpfile();
fwrite($temp, $data);
rewind($temp);
$result = array();
while ($line = fgetcsv($temp)) {
$result[] = $line;
}
fclose($temp);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment