開発メモ

開発用のメモです。

PHPで SJISのCSVを読み込む

<?php

protected function readCsvLine($q=0) {
    $file = new File(APP . DS . "webroot" . DS . "SJIS.csv");
    $content = mb_convert_encoding(file_get_contents($file -> path), "UTF-8", "SJIS");
    $temp = fopen (tempnam($file->path, date("Y-m-d_H_i_s")), "r+");
    fwrite($temp, $content);
    rewind($temp);
    $line = "";
    for ($x = 0; $x < $q; $x++) {
        $line = fgetcsv($temp);
    }
    return $line;
}
Twitter: @asahina_alice