Last active
December 29, 2015 16:59
-
-
Save ishtaka/7701267 to your computer and use it in GitHub Desktop.
[PHP]Excelで作成(編集)されたCSVをPHP(UTF-8)で読み込む
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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