Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- header('content-type: text/plain;charset=utf8');
- function readCSV($path, $hasHeader = true, $encoding = "UTF-16") {
- $contents = file_get_contents($path);
- $contents = iconv($encoding, "UTF-8", $contents);
- $lines = explode("\r\n", $contents);
- $lines = array_filter($lines, 'trim');
- $rows = array_map('str_getcsv', $lines);
- if($hasHeader) {
- $headers = array_shift($rows);
- foreach($rows as &$row) {
- $data = [];
- foreach($row as $idx => $value) {
- $data[$headers[$idx]] = $value;
- }
- $row = $data;
- }
- }
- return $rows;
- }
- $csv = readCSV('google.csv');
- print_r($csv);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement